# lme4 fits mixed-effects models with S4 classes and C++ underneath

> lme4 is the R package for linear and generalized mixed-effects models, built on S4 classes and methods with an RcppEigen layer over Eigen for the linear algebra. It handles arbitrarily nested and crossed random effects, and its cost is a compiled toolchain, a strict release line and a warning-free-printing habit that every user has to learn.

**lme4/lme4** — Mixed-effects models in R using S4 classes and methods with RcppEigen

- Repository: https://github.com/lme4/lme4
- Stars: 699 · Forks: 165
- Language: HTML
- License: NOASSERTION
- Published: 2026-10-21 · Updated: 2026-10-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/lme4-lme4

## What a mixed-effects model is for

lme4 is the R package for mixed-effects models, and it exists because ordinary regression cannot express the structure most repeated-measures data has. When every observation from the same subject, site or classroom is correlated, a fixed-effects model either ignores that correlation or spends parameters on it and runs out of data. A mixed-effects model splits the effect into population-level fixed components and group-level random components, and estimates the variance of the random part rather than treating each group as a separate parameter. The package supports arbitrarily many nested and crossed random effects, which is the practical part that matters: crossed means a subject observed in one condition and another observed in a different one, and nested means subjects within subjects, and neither structure has to be simplified to fit the model. On top of the linear mixed model, lme4 fits generalized linear mixed models and nonlinear mixed models, with the approximation method chosen per fit, either Laplace approximation or adaptive Gauss-Hermite quadrature, and GLMMs accept user-defined families and link functions. It also brings likelihood profiling and parametric bootstrapping, so a fixed-effect test can be turned into a profile of the likelihood or a bootstrap distribution instead of a single p-value.

## S4 classes and methods, not tidyverse objects

The description says it plainly: lme4 is built with S4 classes and methods, and that choice has consequences for how you use it. An S4 object carries a class with formally defined slots, and behaviour is attached to the class through methods rather than dispatched on a class attribute. That means a fitted lme4 object is a structured thing you interrogate with accessors and extractors rather than a data frame you reshape with verbs. If your workflow is built around tibbles and pipes, the friction is real and it is the single most common complaint about the package among users arriving from the tidyverse. The upside is that the structure is explicit and checkable. Because the object has a defined class, methods for summary, prediction, simulation and variance component extraction are part of the contract, and the package can be extended at the class level rather than by wrapping it. The internal machinery sits behind the object model, which is where the performance work happens, and the two layers are worth separating when you read the documentation: the S4 surface is the API you will use, and the numerical core is an implementation detail you should not have to touch.

## RcppEigen over Eigen is where the speed lives

The performance claim in the feature list is specific and points at a stack. lme4 is efficient for large data sets, using algorithms from the Eigen linear algebra package through the RcppEigen interface layer. That is a deliberate three-part choice. Eigen is a header-only C++ template library for matrix operations, RcppEigen is the bridge that lets R code call it without writing raw C++ glue, and the algorithms themselves come from the sparse matrix machinery that mixed-effects fitting needs, because the design matrix of a grouped model is large and sparse. The consequence for the user is that fitting is fast enough to run inside a loop or a simulation, which is what makes the parametric bootstrapping feature practical rather than theoretical. The other consequence is the build. The package contains compiled code, and the installation notes are direct about it: installing from GitHub builds the package from source, which means make and compilers must be present on your system, and you may need to install dependencies by hand, and you can set build_vignettes=FALSE if your system lacks the LaTeX and texi2dvi tools. The CRAN route ships binaries for most platforms, so the compiler tax applies mainly when you install a development version or work on a platform CRAN does not cover.

## Three ways to install, and which one to pick

For a stable release, the documented path is CRAN, and the badge in the README points at the current version there. The development version from GitHub is a single devtools call, and it installs the master branch with its dependencies.

```r
library("devtools"); install_github("lme4/lme4",dependencies=TRUE)
```

That approach requires devtools 1.6.1 or later and, as noted, a working toolchain on your system. The third option avoids the compiler entirely by pulling development binaries from r-universe.

```r
install.packages('lme4', repos = c('https://lme4.r-universe.dev', getOption("repos")[["CRAN"]]))
```

The repository also warns that installation on now-ancient versions of R has not been tested recently, and that recursive package dependencies may impede installation on those versions, with the request to post an issue if you hit it. That note is dated by the R version it names, so treat it as a floor rather than a current statement, and the sections for current R and older R differ. The practical order of preference is CRAN for production work, r-universe when you need a recent development version without a compiler, and install_github only when you are deliberately testing the tip of the branch and have the toolchain to do it.

## A package built by two toolchains at once

The development notes explain that lme4 is worked on with a mixture of traditional R package building tools and tidyverse-style tools, and the list is a good map of the repository. On the traditional side there is documentation written as .Rd files rather than roxygen2, a NEWS file at inst/NEWS.Rd rather than a top-level NEWS.md, classic tests in the tests directory, and some Sweave or knitr format vignettes, especially vignettes/lmer.Rnw. On the tidyverse side there are testthat tests under tests/testthat and a pkgdown website built with pkgdown.extras extensions that allow PDF vignettes, with the site build triggered manually from the pkgdown workflow. GitHub is the primary development repository, issues and pull requests live there, and the CI runs on GitHub actions, activated by putting [run ci] at the end of a commit message rather than by every push. The top level of the repository shows the same mixture, with R/, src/, man/, vignettes/, tests/, testsx/, inst/, data/, docs/, reverse/, misc/ and a _pkgdown.yml configuration, plus a do-roxy script and a LICENSE.note. The Makefile offers the familiar R CMD build, install and check targets, and the check target runs with --as-cran, which is the strictest CRAN check available. Licensing deserves its own note, because the file name is unusual. The repository carries a LICENSE.note rather than a standard LICENSE file, and the licence is filed as a custom one that GitHub cannot classify against its list, so if you redistribute lme4 or ship it inside another product, read that note rather than assuming the GPL or LGPL terms you might associate with older versions of the package.

## Where the help actually lives

The README is explicit about support channels, and the distinctions are worth preserving because they decide where your question will be answered. Usage questions and general mixed model questions go to the r-sig-mixed-models mailing list, with a request to read the info page and subscribe before posting, and a note that the list does not support images or large non-text attachments. Bugs, infelicitous behaviour and wishlist items go to the GitHub issues. Programming questions go to the lme4 tag on StackOverflow and statistics questions to the lme4-nlme tag on CrossValidated. The maintainer's e-mail is for urgent or private communication only. Cross-posting is discouraged unless you are told to, and if you get total silence in one forum the advice is to bump the original thread and mention where and when you asked before. Release notes live in the NEWS file, and recent development is tracked there rather than in a changelog on the front page. Financial support goes to a Global Coding Fund at McMaster University, with the stated intent of paying students to do maintenance and development work, no way to earmark funds for a particular feature, and an invitation to e-mail the maintainers with priorities for a donation.

## Conclusion

Adopt lme4 if your data has grouping structure that a fixed-effects model cannot express and you want a mature, widely used implementation with a CRAN release behind it. Skip it if you cannot install a compiler, since the package is built from source outside the binary channels, or if you need a modern tidyverse object model rather than the S4 classes it is built on. Before you fit your first model, read the NEWS file for the version you install, because the package has changed its handling of convergence over the years, and check that your random effects specification is actually identifiable before trusting any variance component it reports.

## FAQ

### How do I install the development version of lme4 from GitHub?

Run library("devtools"); install_github("lme4/lme4",dependencies=TRUE) from the R console. It installs the master branch and requires devtools 1.6.1 or later, and it builds the package from source, so make and compilers must be installed on your system.

### How do I install lme4 without a C++ compiler?

Use the development binaries from r-universe with install.packages('lme4', repos = c('https://lme4.r-universe.dev', getOption("repos")[["CRAN"]])). The CRAN route also provides binaries for most platforms, and the source build is only needed for GitHub development versions.

### Which kinds of random effects can lme4 fit?

Arbitrarily many nested and crossed random effects. Beyond the linear case, the package fits generalized linear mixed models and nonlinear mixed models via Laplace approximation or adaptive Gauss-Hermite quadrature, and GLMMs accept user-defined families and link functions.

### Where should I ask a question about lme4?

Usage and general mixed model questions go to the r-sig-mixed-models mailing list, bugs and wishlist items to the GitHub issues, programming questions to the lme4 tag on StackOverflow and statistics questions to the lme4-nlme tag on CrossValidated. The maintainer's e-mail is for urgent or private matters only.

## Sources

- [Issues](https://github.com/lme4/lme4/issues)
- [lme4/lme4 on GitHub](https://github.com/lme4/lme4)
- [README](https://github.com/lme4/lme4/blob/master/README.md)
- [Releases](https://github.com/lme4/lme4/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/lme4-lme4
