Solved – Mixed effects log-linear models

categorical datalog-linearmixed model

There are occasions where I would like to fit log-linear models where the independence assumption between observations is violated. It is the normal case that I have multiple observations from each subject. Is there a mixed-effects extension to log-linear models like there are for linear and generalized linear models?

I'm interested in the existence of such a thing in principle, but also its concrete existence in an R library.

Best Answer

Log-linear or Poisson model are part of generalized linear models. Look at the lme4 package which allows for mixed-effects modeling, with family=poisson().

Here is an example of use:

> data(homerun, package="Zelig")
> with(homerun, table(homeruns, month))
        month
homeruns April August July June March May September
       0    36     36   40   26     1  33        30
       1    13     17   11   21     1  14        14
       2     0      3    3    3     0   3         6
       3     1      0    0    1     0   1         0
> library(lme4)
> mod <- glmer(homeruns ~ player + (player - 1 | month), data=homerun, family=poisson())
> summary(mod)
Generalized linear mixed model fit by the Laplace approximation 
Formula: homeruns ~ player + (player - 1 | month) 
   Data: homerun 
   AIC   BIC logLik deviance
 305.8 324.6 -147.9    295.8
Random effects:
 Groups Name          Variance   Std.Dev.   Corr  
 month  playerMcGwire 7.9688e-10 2.8229e-05       
        playerSosa    6.6633e-02 2.5813e-01 0.000 
Number of obs: 314, groups: month, 7

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -0.7949     0.1195  -6.651 2.91e-11 ***
playerSosa   -0.1252     0.2020  -0.620    0.535    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Correlation of Fixed Effects:
           (Intr)
playerSosa -0.592

The scale parameter (useful to check for possible overdispersion) is available through the following slot:

summary(mod)@sigma

(The equivalent for usual GLM would be summary(glm(...))$dispersion).

More information about mixed-effects modeling as implemented in lme4 can be found on R-forge, in the Mixed-effects models project, or the GLMM FAQ, as suggested by @fabians.

The gamm4 package may also be of interest as it allows to fit generalized additive mixed models.

Related Question