Fitting Linear Mixed-Effects Models Using lme4
Written for the Research library (claude-opus-5-5) from the paper text. Original — jstatsoft.org/index.php/jss/article/view/v067i01/946
Summary
Mixed-effects models combine population-level (fixed) and group-level (random) terms. They are widely used but computationally demanding, especially on data with 10^4–10^6 observations. This paper documents how the lme4 package for R fits linear mixed models through its lmer function. Users specify fixed and random terms in a single R formula. lme4 turns that formula into sparse model matrices and a relative covariance factor governed by a parameter vector θ. Fitting is recast as a penalized least squares problem solved with sparse Cholesky decomposition. This yields a profiled deviance or REML criterion that depends only on θ, which a constrained optimizer then minimizes. lmer is organised into four separable modules, and each step is exposed so that developers can build models the formula syntax cannot express, such as pedigree or smoothing-spline models. Compared with nlme, lme4 offers faster linear algebra, simpler handling of crossed random effects, profile-likelihood intervals and GLMM support. The paper is the reference description of a core tool in applied statistics.
Key points
- Modular pipeline. lmer is split into four modules:
lFormula,mkLmerDevfun,optimizeLmerandmkMerMod. The paper describes stable version 1.1-10. - Running example. The sleepstudy data (180 observations, 18 subjects, sleep limited to 3 h per night) is fitted with
Reaction ~ Days + (Days | Subject).- Fixed effects: intercept 251.4 ms, slope 10.47 ms/day.
- Random-effect SDs: 24.74 ms (intercept) and 5.92 ms/day (slope).
- Trade-offs with nlme. nlme remains more convenient for heteroscedastic or autocorrelated residuals and structured covariance matrices.
- Related projects. Descendants include MixedModels (Julia), lme4pureR and the flexLambda branch. gamm4 and blme build on lme4's extension hooks.
- Post-fit tools.
- Profile-based confidence intervals with zeta, density and pairs plots.
predictwith are.formargument to control which random effects are conditioned on.simulate, which supports parametric bootstrap and formula-based power analysis.
Cited by
- Discourse structure and narration: A diachronic view from Germanic
- How focus particles and accents affect attachment
- Integrating syntactic theory and variationist analysis: The structure of negative indefinites in regional dialects of British English
- Investigating the distribution of some (but not all) implicatures using corpora and web-based methods
- Interpreting past epistemic modals in English, Dutch, and French
- Red Teaming Language Models to Reduce Harms: Methods, Scaling Behaviors, and Lessons Learned
- Uniform Information Density and Syntactic Reduction: Revisiting that-Mentioning in English Complement Clauses
- Large Language Models Effectively Leverage Document-level Context for Literary Translation, but Critical Errors Persist
- Thematic role assignment in non-default verb classes: A cross-linguistic comparison of English and German
- Grammatical generalizations and item-specific listing in Hebrew transitivity alternations
- Anticausatives are semantically reflexive in Norwegian, but not in English
- The role of Alternatives in the interpretation of scalars and numbers: Insights from the inference task
- Nucleus Composition in Transition-based Dependency Parsing
- Subject-verb agreement with Seq2Seq transformers: Bigger is better, but still not best
Cite
@article{bates2015fitting,
title = {{Fitting Linear Mixed-Effects Models Using lme4}},
author = {Bates, Douglas and Mächler, Martin and Bolker, Ben and Walker, Steve},
journal = {Journal of Statistical Software 67(1)},
year = {2015},
eprint = {1406.5823},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1406.5823}
}References
- Bates D (2015). MixedModels: A Julia Package for Fitting (Statistical) Mixed-Effects Models. Julia package version 0.3-22, URL https://github.com/dmbates/MixedModels.jl. ↗
- Bates D, Maechler M (2015). Matrix: Sparse and Dense Matrix Classes and Methods. R package version 1.2-2, URL http://CRAN.R-project.org/package=Matrix. ↗
- Bates D, Maechler M, Bolker B, Walker S (2015). lme4: Linear Mixed-Effects Models Using Eigen and S4. R package version 1.1-10, URL http://CRAN.R-project.org/package= lme4. ↗
- Bates D, Mullen KM, Nash JC, Varadhan R (2014). minqa: Derivative-Free Optimization Algorithms by Quadratic Approximation. R package version 1.2.4, URL http://CRAN. R-project.org/package=minqa. find
- Bates D, Walker S (2013). lme4pureR: lme4 in Pure R. R package version 0.1-0, URL https://github.com/lme4/lme4pureR. ↗
- Bates DM, DebRoy S (2004). “Linear Mixed Models and Penalized Least Squares.” Journal of Multivariate Analysis, 91(1), 1–17. doi:10.1016/j.jmva.2004.04.013. — [doi:10.1016/j.jmva.2004.04.013](https://doi.org/10.1016/j.jmva.2004.04.013) find
- Bates DM, Watts DG (1988). Nonlinear Regression Analysis and Its Applications. John Wiley & Sons, Hoboken, NJ. doi:10.1002/9780470316757. — [doi:10.1002/9780470316757](https://doi.org/10.1002/9780470316757) find
- Belenky G, Wesensten NJ, Thorne DR, Thomas ML, Sing HC, Redmond DP, Russo MB, Balkin TJ (2003). “Patterns of Performance Degradation and Restoration During Sleep Restriction and Subsequent Recovery: A Sleep Dose-Response Study.” Journal of Sleep Research, 12(1), 1–12. doi:10.1046/j.1365-2869.2003.00… — [doi:10.1046/j.1365-2869.2003.00337.x](https://doi.org/10.1046/j.1365-2869.2003.00337.x) find
- Bezanson J, Karpinski S, Shah VB, Edelman A (2012). “Julia: A Fast Dynamic Language for Technical Computing.” arXiv:1209.5145 [cs.PL], URL http://arxiv.org/abs/1209.5145. — [arXiv:1209.5145](https://arxiv.org/abs/1209.5145) ↗
- Bolker BM, Gardner B, Maunder M, Berg CW, Brooks M, Comita L, Crone E, Cubaynes S, Davies T, de Valpine P, Ford J, Gimenez O, Kéry M, Kim EJ, Lennert-Cody C, Magnusson A, Martell S, Nash J, Nielsen A, Regetz J, Skaug H, Zipkin E (2013). “Strategies for Fitting Nonlinear Ecological Models in R, AD Mo… — [doi:10.1111/2041-210x.12044](https://doi.org/10.1111/2041-210x.12044) find
- Canty A, Ripley B (2015). boot: Bootstrap R (S-PLUS) Functions. R package version 1.3-17, URL http://CRAN.R-project.org/package=boot. ↗
- Chambers JM (1993). “Linear Models.” In JM Chambers, TJ Hastie (eds.), Statistical Models in S, chapter 4, pp. 95–144. Chapman & Hall. find
- Chen Y, Davis TA, Hager WW, Rajamanickam S (2008). “Algorithm 887: CHOLMOD, Supernodal Sparse Cholesky Factorization and Update/Downdate.” ACM Transactions on Mathematical Software, 35(3), 22:1–22:14. doi:10.1145/1391989.1391995. — [doi:10.1145/1391989.1391995](https://doi.org/10.1145/1391989.1391995) find
- Chung Y, Rabe-Hesketh S, Dorie V, Gelman A, Liu J (2013). “A Nondegenerate Penalized Likelihood Estimator for Variance Parameters in Multilevel Models.” Psychometrika, 78(4), 685–709. find
- Cook RD, Weisberg S (1982). Residuals and Influence in Regression. Chapman and Hall, New York. find
- Davis T (2006). Direct Methods for Sparse Linear Systems. SIAM, Philadelphia, PA. doi: 10.1137/1.9780898718881. — [doi:10.1137/1.9780898718881](https://doi.org/10.1137/1.9780898718881) find
- Davis TA, et al. (2015). SuiteSparse: A Suite of Sparse Matrix Software. Version 4.4-5, URL http://www.suitesparse.com/. ↗
- Davison AC, Hinkley DV (1997). Bootstrap Methods and Their Applications. Cambridge University Press, Cambridge, England. find
- Doran H, Bates D, Bliese P, Dowling M (2007). “Estimating the Multilevel Rasch Model: With the lme4 Package.” Journal of Statistical Software, 20(2), 1–18. doi:10.18637/jss. v020.i02. — [doi:10.18637/jss](https://doi.org/10.18637/jss) find
- Dorie V (2015). blme: Bayesian Linear Mixed-Effects Models. R package version 1.0-4, URL http://CRAN.R-project.org/package=blme. ↗
- Efron B, Morris C (1977). “Stein’s Paradox in Statistics.” Scientific American, 236, 119–127. doi:10.1038/scientificamerican0577-119. — [doi:10.1038/scientificamerican0577-119](https://doi.org/10.1038/scientificamerican0577-119) find
- Gelman A (2005). “Analysis of Variance – Why It Is More Important than Ever.” The Annals of Statistics, 33(1), 1–53. doi:10.1214/009053604000001048. — [doi:10.1214/009053604000001048](https://doi.org/10.1214/009053604000001048) find
- Gelman A, Carlin JB, Stern HS, Dunson DB, Vehtari A, Rubin DB (2013). Bayesian Data Analysis. CRC Press. find
- Gelman A, Hill J (2006). Data Analysis Using Regression and Multilevel/Hierarchical Models. Cambridge University Press, Cambridge, England. find
- Golub GH, Pereyra V (1973). “The Differentiation of Pseudo-Inverses and Nonlinear Least Squares Problems Whose Variables Separate.” SIAM Journal on Numerical Analysis, 10(2), 413–432. doi:10.1137/0710036. — [doi:10.1137/0710036](https://doi.org/10.1137/0710036) find
- Guennebaud G, Jacob B, and others (2015). Eigen3. URL http://eigen.tuxfamily.org/. ↗
- Henderson Jr CR (1982). “Analysis of Covariance in the Mixed Model: Higher-Level, Nonho-mogeneous, and Random Regressions.” Biometrics, 38(3), 623–640. doi:10.2307/2530044. — [doi:10.2307/2530044](https://doi.org/10.2307/2530044) find
- Horn RA, Zhang F (2005). “Basic Properties of the Schur Complement.” In F Zhang (ed.), The Schur Complement and Its Applications, volume 4 of Numerical Methods and Algorithms, pp. 17–46. Springer-Verlag. doi:10.1007/0-387-24273-2\_2. — [doi:10.1007/0-387-24273-2\_2](https://doi.org/10.1007/0-387-24273-2_2) find
- Johnson SG (2014). “The NLopt Nonlinear-Optimization Package.” ab-initio.mit.edu/nlopt. find
- Kenward MG, Roger JH (1997). “Small Sample Inference for Fixed Effects from Restricted Maximum Likelihood.” Biometrics, 53(3), 983–997. doi:10.2307/2533558. — [doi:10.2307/2533558](https://doi.org/10.2307/2533558) find
- Khatri CG, Rao CR (1968). “Solutions to Some Functional Equations and Their Applications to Characterization of Probability Distributions.” Sankhyā: The Indian Journal of Statistics A, 30(2), 167–180. find
- Klein K, Neira J (2013). “Nelder-Mead Simplex Optimization Routine for Large-Scale Problems: A Distributed Memory Implementation.” Computational Economics, 43(4), 447–461. doi:10.1007/s10614-013-9377-8. — [doi:10.1007/s10614-013-9377-8](https://doi.org/10.1007/s10614-013-9377-8) find
- Laird NM, Ware JH (1982). “Random-Effects Models for Longitudinal Data.” Biometrics, 38(4), 963–974. doi:10.2307/2529876. — [doi:10.2307/2529876](https://doi.org/10.2307/2529876) find
- Loy A, Hofmann H (2014). “HLMdiag: A Suite of Diagnostics for Hierarchical Linear Models in R.” Journal of Statistical Software, 56(5), 1–28. doi:10.18637/jss.v056.i05. — [doi:10.18637/jss.v056.i05](https://doi.org/10.18637/jss.v056.i05) find
- Nash JC, Varadhan R (2011). “Unifying Optimization Algorithms to Aid Software System Users: optimx for R.” Journal of Statistical Software, 43(9), 1–14. doi:10.18637/jss. v043.i09. — [doi:10.18637/jss](https://doi.org/10.18637/jss) find
- Nieuwenhuis R, Te Grotenhuis M, Pelzer B (2012). “Influence.ME: Tools for Detecting Influential Data in Mixed Effects Models.” The R Journal, 4(2), 38–47. find
- Pinheiro J, Bates D, DebRoy S, Sarkar D, R Core Team (2015). nlme: Linear and Nonlinear Mixed Effects Models. R package version 3.1-122, URL http://CRAN.R-project.org/ package=nlme. ↗
- Pinheiro JC, Bates DM (1996). “Unconstrained Parametrizations for Variance-Covariance Matrices.” Statistics and Computing, 6(3), 289–296. doi:10.1007/bf00140873. — [doi:10.1007/bf00140873](https://doi.org/10.1007/bf00140873) find
- Pinheiro JC, Bates DM (2000). Mixed-Effects Models in S and S-PLUS. Springer-Verlag. find
- Powell MJD (2009). “The BOBYQA Algorithm for Bound Constrained Optimization Without Derivatives.” Technical Report DAMTP 2009/NA06, Centre for Mathematical Sciences, University of Cambridge, Cambridge, England. URL http://www.damtp.cam.ac. uk/user/na/NA\_papers/NA2009\_06.pdf. ↗
- R Core Team (2015). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. URL http://www.R-project.org/. ↗
- Sánchez-Espigares JA, Ocaña J (2009). “An R Implementation of Bootstrap Procedures for Mixed Models.” Conference presentation, useR! Accessed 2014-05-25, URL http://www. R-project.org/conferences/useR-2009/slides/SanchezEspigares+Ocana.pdf. find
- Sarkar D (2008). lattice: Multivariate Data Visualization with R. Springer-Verlag, New York. URL http://lmdvr.R-Forge.R-project.org. ↗
- Satterthwaite FE (1946). “An Approximate Distribution of Estimates of Variance Components.” Biometrics Bulletin, 2(6), 110–114. doi:10.2307/3002019. — [doi:10.2307/3002019](https://doi.org/10.2307/3002019) find
- Vaida F, Blanchard S (2005). “Conditional Akaike Information for Mixed-Effects Models.” Biometrika, 92(2), 351–370. doi:10.1093/biomet/92.2.351. — [doi:10.1093/biomet/92.2.351](https://doi.org/10.1093/biomet/92.2.351) find
- Wood S, Scheipl F (2014). gamm4: Generalized Additive Mixed Models Using mgcv and lme4. R package version 0.2-3, URL http://CRAN.R-project.org/package=gamm4. ↗