Mixed (aka multilevel or hierarchical) models are linear models that include both fixed effects and random effects. They are used to model longitudinal or nested data.
Overview
Mixed models are linear models that include both fixed effects and random effects*. They are used to model longitudinal or nested data; such data do not have independent errors and mixed models can account for the arising correlations. Mixed models are also known as multilevel or hierarchical linear models.
A classic example is the estimation of test scores of students: if test scores are correlated within classes, schools, districts, etc., mixed models allow the modeler to simultaneously estimate the differences between individual students and between the groups to which they belong (with the possibility of including covariates at all levels).
In a mixed model, study units are thought of as sampled from a population; the fixed effects are estimates of the population average effect, whereas the random effects are specific to the study units. In matrix form, a mixed effects model might be: $$ \bf Y=X\boldsymbol\beta + Zb + \boldsymbol\varepsilon $$ where $\bf X$ is the design matrix, $\boldsymbol\beta$ is a vector of the population average effects, $\bf Z$ is a subset of the columns of $\bf X$, $\bf b$ is a vector of the unit specific deviations from the population effects, and $\boldsymbol \varepsilon$ is a vector of random errors.
* Note that here we follow terminology used in statistics, social sciences, and biostatistics; similar terminology ("fixed effects", "random effects") is also used in econometrics, but the meaning is different.
References
StatsExchangers often recommend the following resources for learning more about mixed models:
- Modern Applied Statistics with S by Venables and Ripley (2002)
- "Random Effects Models for Longitudinal Data" (Biometrics 38:963—974) by Laird and Ware (1982)
- Analyzing linguistic data by Baayen (2008)
- Hierarchical Linear Models by Raudenbush and Bryk (2001)
- Data Analysis Using Regression and Multilevel/Hierarchical Models by Gelman and Hill (2006)
- Applied Longitudinal Data Analysis by Singer and Willett (2003).
Software packages
Mixed models are available in the following statistical packages:
lme4
,nlme
,lmerTest
,gamm4
,glmmTMB
,GLMMadaptive
,mmrm
,glmmLasso
,MCMCglmm
,glmmPQL
,rstanarm
andbrms
for RPROC MIXED
,NLMIXED
andGLIMMIX
for SASMLwiN
xtreg
,xtmixed
,xtlogit
,xtmelogit
,xtmepoisson
, and otherxt*
commands; user-contributed packageGLLAMM
for StataMplus
HLM
statsmodels
andPyMC4
for PythonMixedModels.jl
for Julia