Skip to main content
added 72 characters in body
Source Link

I am using the glmer function (lme4 package) to get estimations in a Poisson regression model (generalized linear model). I wanted to compare the estimations for the fixed effects with those obtained with the glm function. I was surprised to see big differences ! I know that glmer includes random effect; but that does not suffice to explain theses differences.

Could someone explain to me what I missed in my approach ?

EDIT and ANSWER : Put an offset term in both glmand glmer

    library(surrosurv)
    library(survival)
    library(lme4)

     data(colon)
     colon1 = subset(colon, etype == 1)
    # Poissonization

   don_pois = poissonize(colon1, interval.width = 365.25, factors = c ('surg', 'rx'), compress = FALSE)
   names(don_pois)[3] = 'trt'; names(don_pois)[4] = 'trialref'
    

    fitpoi_glmer   <- glmer(
                    formula = event ~ -1 + interval + ( 1 | trialref ),
                    data = don_pois,
                    family = poisson(link = "log")
                     )
    
    
    fitpoi_glm <- glm(
      formula = event ~ -1+ interval + offset(log(time)), 
      data = don_pois, 
      family = poisson(link = "log")
    )
    

    summary(fitpoi_glmer)$coefficients 
    summary(fitpoi_glm)$coefficients

# Survival graphics

   fixed.coef.glmer = summary(fitpoi_glmer)$coefficients[,'Estimate']
     risks0 = exp(fixed.coef.glmer[grep("(?!.*:)interval.*", names(fixed.coef.glmer), perl = T)]) * 365.25
     surv0 <- c(1,exp(-cumsum(risks0)))
     x = seq(0, max(colon1$time), length.out = length(surv0))
     plot(x, surv0, type ='l', col = 'blue', lwd = 2)
  
     
     risks3 = exp(coef(fitpoi_glm)[grep("(?!.*:)interval.*", names(coef(fitpoi_glm)), perl = T)]) * 365.25
     surv3 <- c(1,exp(-cumsum(risks3)))
     lines(x, surv3, type ='l', col = 'pink', lwd = 2)
     
     # Comparison with survfit
     lines(survfit(Surv(time, status)~1, data = colon1 ), lty = 2, conf.int= FALSE)

I am using the glmer function (lme4 package) to get estimations in a Poisson regression model (generalized linear model). I wanted to compare the estimations for the fixed effects with those obtained with the glm function. I was surprised to see big differences ! I know that glmer includes random effect; but that does not suffice to explain theses differences.

Could someone explain to me what I missed in my approach ?

    library(surrosurv)
    library(survival)
    library(lme4)

     data(colon)
     colon1 = subset(colon, etype == 1)
    # Poissonization

   don_pois = poissonize(colon1, interval.width = 365.25, factors = c ('surg', 'rx'), compress = FALSE)
   names(don_pois)[3] = 'trt'; names(don_pois)[4] = 'trialref'
    

    fitpoi_glmer   <- glmer(
                    formula = event ~ -1 + interval + ( 1 | trialref ),
                    data = don_pois,
                    family = poisson(link = "log")
                     )
    
    
    fitpoi_glm <- glm(
      formula = event ~ -1+ interval + offset(log(time)), 
      data = don_pois, 
      family = poisson(link = "log")
    )
    

    summary(fitpoi_glmer)$coefficients 
    summary(fitpoi_glm)$coefficients

# Survival graphics

   fixed.coef.glmer = summary(fitpoi_glmer)$coefficients[,'Estimate']
     risks0 = exp(fixed.coef.glmer[grep("(?!.*:)interval.*", names(fixed.coef.glmer), perl = T)]) * 365.25
     surv0 <- c(1,exp(-cumsum(risks0)))
     x = seq(0, max(colon1$time), length.out = length(surv0))
     plot(x, surv0, type ='l', col = 'blue', lwd = 2)
  
     
     risks3 = exp(coef(fitpoi_glm)[grep("(?!.*:)interval.*", names(coef(fitpoi_glm)), perl = T)]) * 365.25
     surv3 <- c(1,exp(-cumsum(risks3)))
     lines(x, surv3, type ='l', col = 'pink', lwd = 2)
     
     # Comparison with survfit
     lines(survfit(Surv(time, status)~1, data = colon1 ), lty = 2, conf.int= FALSE)

I am using the glmer function (lme4 package) to get estimations in a Poisson regression model (generalized linear model). I wanted to compare the estimations for the fixed effects with those obtained with the glm function. I was surprised to see big differences ! I know that glmer includes random effect; but that does not suffice to explain theses differences.

Could someone explain to me what I missed in my approach ?

EDIT and ANSWER : Put an offset term in both glmand glmer

    library(surrosurv)
    library(survival)
    library(lme4)

     data(colon)
     colon1 = subset(colon, etype == 1)
    # Poissonization

   don_pois = poissonize(colon1, interval.width = 365.25, factors = c ('surg', 'rx'), compress = FALSE)
   names(don_pois)[3] = 'trt'; names(don_pois)[4] = 'trialref'
    

    fitpoi_glmer   <- glmer(
                    formula = event ~ -1 + interval + ( 1 | trialref ),
                    data = don_pois,
                    family = poisson(link = "log")
                     )
    
    
    fitpoi_glm <- glm(
      formula = event ~ -1+ interval + offset(log(time)), 
      data = don_pois, 
      family = poisson(link = "log")
    )
    

    summary(fitpoi_glmer)$coefficients 
    summary(fitpoi_glm)$coefficients

# Survival graphics

   fixed.coef.glmer = summary(fitpoi_glmer)$coefficients[,'Estimate']
     risks0 = exp(fixed.coef.glmer[grep("(?!.*:)interval.*", names(fixed.coef.glmer), perl = T)]) * 365.25
     surv0 <- c(1,exp(-cumsum(risks0)))
     x = seq(0, max(colon1$time), length.out = length(surv0))
     plot(x, surv0, type ='l', col = 'blue', lwd = 2)
  
     
     risks3 = exp(coef(fitpoi_glm)[grep("(?!.*:)interval.*", names(coef(fitpoi_glm)), perl = T)]) * 365.25
     surv3 <- c(1,exp(-cumsum(risks3)))
     lines(x, surv3, type ='l', col = 'pink', lwd = 2)
     
     # Comparison with survfit
     lines(survfit(Surv(time, status)~1, data = colon1 ), lty = 2, conf.int= FALSE)
Source Link

Why do I get so different estimations with glm and glmer?

I am using the glmer function (lme4 package) to get estimations in a Poisson regression model (generalized linear model). I wanted to compare the estimations for the fixed effects with those obtained with the glm function. I was surprised to see big differences ! I know that glmer includes random effect; but that does not suffice to explain theses differences.

Could someone explain to me what I missed in my approach ?

    library(surrosurv)
    library(survival)
    library(lme4)

     data(colon)
     colon1 = subset(colon, etype == 1)
    # Poissonization

   don_pois = poissonize(colon1, interval.width = 365.25, factors = c ('surg', 'rx'), compress = FALSE)
   names(don_pois)[3] = 'trt'; names(don_pois)[4] = 'trialref'
    

    fitpoi_glmer   <- glmer(
                    formula = event ~ -1 + interval + ( 1 | trialref ),
                    data = don_pois,
                    family = poisson(link = "log")
                     )
    
    
    fitpoi_glm <- glm(
      formula = event ~ -1+ interval + offset(log(time)), 
      data = don_pois, 
      family = poisson(link = "log")
    )
    

    summary(fitpoi_glmer)$coefficients 
    summary(fitpoi_glm)$coefficients

# Survival graphics

   fixed.coef.glmer = summary(fitpoi_glmer)$coefficients[,'Estimate']
     risks0 = exp(fixed.coef.glmer[grep("(?!.*:)interval.*", names(fixed.coef.glmer), perl = T)]) * 365.25
     surv0 <- c(1,exp(-cumsum(risks0)))
     x = seq(0, max(colon1$time), length.out = length(surv0))
     plot(x, surv0, type ='l', col = 'blue', lwd = 2)
  
     
     risks3 = exp(coef(fitpoi_glm)[grep("(?!.*:)interval.*", names(coef(fitpoi_glm)), perl = T)]) * 365.25
     surv3 <- c(1,exp(-cumsum(risks3)))
     lines(x, surv3, type ='l', col = 'pink', lwd = 2)
     
     # Comparison with survfit
     lines(survfit(Surv(time, status)~1, data = colon1 ), lty = 2, conf.int= FALSE)