Compute confidence intervals for predicted values in glm R same as proc genmod SAS
1
0
Entering edit mode
6.2 years ago

Hi everyone,

My current goal is to translate a SAS program to R. My issue here is that I can't find the equivalence/how to compute predicted values for a glm model as the ones I get in SAS.

I have found the following explanations in SAS documentation : https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_genmod_sect045.htm But I have troubles to translate the formula with a concrete code in R, specially concerning the covariance ...

For now I have computed the CI the following way (I'm working with lists)

# GLM
  models <- lapply(combia, function (x) {glm(cbind(n,s-n) ~ scm, family = binomial, data = x)})

  # Get confidence intervals
  p <- lapply(models, function (x) {predict(x, type = "link", se.fit = TRUE)})

  lowerlogit <- lapply(p, function(x) {x$fit - 1.96*x$se.fit})
  upperlogit <- lapply(p, function(x) {x$fit + 1.96*x$se.fit})

  borneinf <- lapply(lowerlogit, function(x) {exp(x)/(1+exp(x))})
  bornesup <- lapply(upperlogit, function(x) {exp(x)/(1+exp(x))})

But I don't get the same CI as SAS, and it's a problem for me in the futures steps.

I hope some of you would be able to help me on that, that would be so helpful !!

Thanks in advance

R • 1.9k views
ADD COMMENT
0
Entering edit mode
6.2 years ago

What you're doing seems OK at first glance. The difference could be in the way the covariance matrix is estimated. This blog post and the referenced SO post might help. Another way could be to use the glm.predict package.

ADD COMMENT

Login before adding your answer.

Traffic: 1779 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6