Linear mixed model formulation
By Deependra Dhakal in R Plant Breeding
December 9, 2018
Introduction
Mixed models are quite tricky, in that, while being very powerful extensions of linear models, they are somewhat difficult to conceptualize and otherwise to specify. Mixed models have, in addition to usual fixed effect combination of factors, random effects structure. These structure need to be specified in the model formula in R
. While formula specification of a model is unique in it’s own respect, the formuala expression too leads to an object with differnt properties than a regular R
object. Although, the complexity of formula syntax can arbitrary (constrained by classess and methods working on that), a general guideline is applicable for most of the mixed modeling utilities. These include: lme4
, nlme
, glmmADMB
and glmmTMB
.
Here, I steal a very useful tabulation, published in Mixed Models FAQ by Ben Bolker, of different patterns in model formula specification.
Interpretation of model formula
Formula | Meaning |
---|---|
(1|group) |
random group intercept |
(x|group) = (1+x|group) |
random slope of x within group with correlated intercept |
(0+x|group) = (-1+x|group) |
random slope of x within group: no variation in intercept |
(1|group) + (0+x|group) |
uncorrelated random intercept and random slope within group |
(1|site/block) = (1|site)+(1|site:block) |
intercept varying among sites and among blocks within sites (nested random effects) |
site+(1|site:block) |
fixed effect of sites plus random variation in intercept among blocks within sites |
(x|site/block) = (x|site)+(x|site:block) = (1 + x|site)+(1+x|site:block) |
slope and intercept varying among sites and among blocks within sites |
(x1|site)+(x2|block) |
two different effects, varying at different levels |
x*site+(x|site:block) |
fixed effect variation of slope and intercept varying among sites and random variation of slope and intercept among blocks within sites |
(1|group1)+(1|group2) |
intercept varying among crossed random effects (e.g. site, year) |