Skip to content
Prev 19632 / 20628 Next

A GLMER Question

On 12/13/21 4:36 PM, Jamie Dallas wrote:
I don't necessarily see why you should expect the slopes to be 
invariant; GLMs don't have the same properties as LMs, even with an 
identity link. "Small" will be context-dependent.  If this makes much of 
a difference to your results, or if you have more than a few zero 
values, you might need to think about a more principled approach such as 
a hurdle model ...

Example:

library(lme4)
dd <- data.frame(x = runif(100),
                  f = factor(rep(1:10, 10)))
set.seed(101)
dd$y <- simulate(~ x + (1|f),
                  family = Gamma(link = "identity"),
                  newdata = dd,
                  newparams = list(beta = rep(1,2),
                                   theta = 1,
                                   sigma = 1))[[1]]
dd$y[sample(nrow(dd), size = 10)] <- 0

fitf <- function(off) {
     g1 <- glmer(y + off ~ x + (1|f),
                 family = Gamma(link = "identity"),
                 data = dd)
     return(fixef(g1))
}

try(fitf(0))
offvec <- 10^c((-5):(-2))
cbind(offvec, t(sapply(offvec, fitf)))


      offvec (Intercept)           x
[1,]  1e-05    1.408488 -0.08994451
[2,]  1e-04    1.408578 -0.08994445
[3,]  1e-03    1.409508 -0.09000147
[4,]  1e-02    1.085238  0.45049626
 >

try(fitf(0))
offvec <- 10^c((-5):(-2))
cbind(offvec, t(sapply(offvec, fitf)))