R – How to Back-Transform Standard Errors from glm() on the Link Scale

generalized linear modelr

My (edited) questions are:

  1. Does glm() provide Std.Errors for the transformed or untransformed parameters?
  2. If Std.Errors are provided on the scale of the link function, how to obtain them for the parameters on the original (i.e. untransformed) scale?

As an example, given the dataset:

set.seed(100)
dd <- data.frame(
                group = c(rep("group1", 100),rep("group2", 100)),
                values = c(rpois(n=100, lambda=2), rpois(n=100, lambda=7))
                )

enter image description here

I computed the following summary statistics:

library(doBy)
logmean <- function(x){
  log(mean(x))
  }
ss <- summaryBy(values ~ group, data=dd, 
            FUN=c(length, logmean, mean, var, sd)
                )
ss$SE.normal <- sqrt(ss$values.var/(ss$values.length-1))
ss$sd.Poiss <- sqrt(ss$values.mean)
ss$se.Poiss <- sqrt(ss$values.mean/ss$values.length)
ss <- cbind(ss[,"group"], round(ss[,-1],3))
names(ss) <- c("group", "N", "log.mean", "mean", "variance", "sd", "SE","sd.Poiss","se.Poiss")

Object ss looks like this:

   group   N log.mean mean variance    sd    SE sd.Poiss se.Poiss
1 group1 100    0.723 2.06    1.653 1.286 0.129    1.435    0.144
2 group2 100    1.937 6.94    8.340 2.888 0.290    2.634    0.263

I then compared these results with those computed by glm():

    glm1 <- glm(values ~ group, data=dd, family="poisson"(link = "log"))

ss$log.mean[1] coincides with glm1$coef[1] and ss$log.mean[2] coincides with glm1$coef[1] + glm1$coef[2], but the Std.Errors provided by glm() do not have any correspondence with those I calculated in table ss:

summary(glm1)$coefficients[, 2]
(Intercept) groupgroup2 
 0.06967330  0.07934287

[Note: while mean = exp(log(mean)), the Std.Error of the mean does not equals to exp(summary(glm1)$coefficients[,2])].

Best Answer

This can be done using the package 'emmeans'

library(emmeans)
df = emmeans (glm1,  ~ group, type = "response")
data.frame(df)[,3]

[1] 0.1435270 0.2634388