Skip to content
Celeus

Linear mixed-effects model (random intercept)

Shown in the app as mixed_model. Part of the method reference, under Mixed-effects models.

When to use

Continuous outcome with repeated or clustered measurements (multiple rows per subject or site): fixed-effect predictors plus a per-cluster random intercept.

What you provide

  • Outcome: one numeric column.
  • Predictors: one or more columns.
  • Cluster (subject or site): one column identifying the cluster.

You can also add a random slope: one numeric predictor whose effect is allowed to differ between clusters.

Options

Missing data

  • Complete case (listwise deletion)

Multiple comparisons

  • Not adjustable for this method. Where it makes post-hoc comparisons, the procedure applies its own correction.

Confidence level

Every interval in the result is reported at the level you choose:

  • 90%
  • 95%
  • 99%

Other methods under Mixed-effects models:

Guides that discuss this method

How to read the output

A linear mixed-effects model analyses a numeric outcome measured repeatedly, or in groups: several visits per patient, several pupils per school, several plates per batch. Each cluster (the patient, school or batch) gets its own baseline through a random intercept, and you can also let one numeric predictor that changes within clusters, such as time, have its own slope in each cluster. Only rows with a value for the outcome, every predictor and the cluster are used, and the number of rows and clusters analysed is reported.

The headline test. The model is fitted by restricted maximum likelihood (REML). The first predictor is tested with an F-test whose denominator degrees of freedom come from the Kenward-Roger approximation, which is the usual small-sample choice and reproduces the paired t-test exactly in a simple balanced design. When the first predictor is a factor with three or more levels, the test covers all its levels together and there is no single estimate; the pairwise comparisons show which levels differ. Above 20,000 rows, where Kenward-Roger becomes slow, the Satterthwaite approximation is used instead and the results say so; at that size the two agree closely.

Coefficients and confidence intervals. The table of coefficients lists each fixed effect with its standard error, degrees of freedom, t statistic, p-value and confidence interval. The interval uses the same degrees of freedom as the test beside it, so a p-value and its interval never come from different reference distributions. You can choose a 90%, 95% or 99% confidence level, and every interval in the result uses it.

Intraclass correlation and variance components. For a model with a random intercept only, the intraclass correlation (ICC) is the share of the variation that lies between clusters rather than within them, reported with a profile-likelihood confidence interval. With a random slope the between-cluster share depends on the value of the slope variable, so no single ICC is reported. The variance components table gives the between-cluster standard deviations, their correlation and the residual standard deviation; for a random-intercept model of moderate size each comes with a profile-likelihood interval.

Checks and limits. Celeus checks the normality of the residuals and of the estimated cluster effects (Shapiro-Wilk), names which variance component is at zero when the fit is singular, and refuses a random slope on a predictor that never changes within a cluster. With fewer than five clusters it notes that the between-cluster variance rests on very few clusters; five is a rule of thumb, and if the clusters are the whole population of interest a fixed effect for the cluster may serve better. Missing values are handled by complete-case analysis only. For the mixed-effects logistic and Poisson models, every number is reproduced by the downloadable R script, with one stated limit: a generalized mixed model’s Wald standard errors come from a finite-difference Hessian; re-running the script in a different R session can change them in the fifth significant digit (the estimate in the ninth).

Sources: Laird NM, Ware JH (1982), Biometrics 38(4):963-974, doi:10.2307/2529876. Kenward MG, Roger JH (1997), Biometrics 53(3):983-997, doi:10.2307/2533558. Bates D, Machler M, Bolker B, Walker S (2015), Journal of Statistical Software 67(1):1-48, doi:10.18637/jss.v067.i01. Kuznetsova A, Brockhoff PB, Christensen RHB (2017), Journal of Statistical Software 82(13):1-26, doi:10.18637/jss.v082.i13.

Worked examples

Celeus's result on a published or illustrative dataset, next to an independent computation and, where one exists, a published value. The data themselves are not reproduced here.

lme4::sleepstudy

  • Source: Published dataset distributed with an R package
  • Licence: lme4 (GPL)
  • Reference: Belenky et al. (2003), J. Sleep Research 12
QuantityCeleusIndependent computationPublished valueAgrees
Estimate10.467310.467310.47Yes
Confidence interval7.20595, 13.728607.20595, 13.72860-Yes
Standard deviation (or correlation) of each random effect24.7407000, 5.9221400, 0.0655512, 25.591800024.7407000, 5.9221400, 0.0655512, 25.5918000-Yes
Number of observations180180-Yes
Test statistic45.85345.853-Yes
p-value3.26381e-063.26381e-06-Yes
Denominator degrees of freedom for the first predictor1717-Yes

lme4::sleepstudy

  • Source: Published dataset distributed with an R package
  • Licence: lme4 (GPL)
  • Reference: Belenky et al. (2003), J. Sleep Research 12; the ICC and its profile interval are an independent computation (a dense-matrix REML written out in base R)
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic169.401169.401-Yes
p-value6.4126e-276.4126e-27-Yes
Denominator degrees of freedom for the first predictor161161-Yes
Confidence interval8.8791, 12.05558.8791, 12.0555-Yes
Effect size0.5893090.589309-Yes
Effect size confidence interval0.412846, 0.7653580.412846, 0.765358-Yes

MASS::shoes

  • Source: Published dataset distributed with an R package
  • Licence: MASS (GPL)
  • Reference: Box, Hunter & Hunter (1978); the pbkrtest 0.5.5 installed vignette 'a01-pbkrtest' (Halekoh & Hojsgaard) prints the Kenward-Roger F, its df and p for this design
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic11.21511.21511.215Yes
p-value0.008538780.008538780.008539Yes
Confidence interval0.133046, 0.6869540.133046, 0.686954-Yes

MASS::shoes

  • Source: Published dataset distributed with an R package
  • Licence: MASS (GPL)
  • Reference: Box, Hunter & Hunter (1978); the pbkrtest 0.5.5 installed vignette 'a01-pbkrtest' deletes rows 1 and 12 and prints the Kenward-Roger F, its fractional df and p
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic5.989325.989325.9893Yes
p-value0.04417640.04417640.04418Yes
Denominator degrees of freedom for the first predictor7.02197.02197.0219Yes

nlme::ergoStool

  • Source: Published dataset distributed with an R package
  • Licence: nlme (GPL)
  • Reference: Pinheiro & Bates (2000), Mixed-Effects Models in S and S-PLUS, Section 1.2: F = 22.36 on 3 and 24 df for Type, as printed by the nlme package's own run of that section's code; p and the post-hoc labels are independent computations
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic22.355622.355622.36Yes
p-value3.93456e-073.93456e-07-Yes
Degrees of freedom3,243,24-Yes
First group of each pairwise comparisonT1, T1, T1, T2, T2, T3T1, T1, T1, T2, T2, T3-Yes
Second group of each pairwise comparisonT2, T3, T4, T3, T4, T4T2, T3, T4, T3, T4, T4-Yes

nlme::Orthodont

  • Source: Published dataset distributed with an R package
  • Licence: nlme (GPL)
  • Reference: Potthoff & Roy (1964), Biometrika 51; the F, p, interval and variance components are an independent computation (nlme::lme, REML, a different fitting engine)
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic9.29219.2921-Yes
p-value0.005375060.00537506-Yes
Confidence interval1.02042, 3.621631.02042, 3.62163-Yes
Variance of each random effect3.26678, 2.049463.26678, 2.04946-Yes
Whether each predictor varies between or within clustersbetween, withinbetween, within-Yes

datasets::ChickWeight

  • Source: Published dataset distributed with an R package
  • Licence: base R (GPL)
  • Reference: Crowder & Hand (1990), Analysis of Repeated Measures, Example 5.3; the reference is pbkrtest called directly, the package the engine calls (a wiring check)
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic6.273846.27384-Yes
p-value0.001178220.00117822-Yes
Denominator degrees of freedom for the first predictor45.521845.5218-Yes
Smallest number of rows in a cluster22-Yes
Largest number of rows in a cluster1212-Yes
First group of each pairwise comparisonD1, D1, D1, D2, D2, D3D1, D1, D1, D2, D2, D3-Yes
Second group of each pairwise comparisonD2, D3, D4, D3, D4, D4D2, D3, D4, D3, D4, D4-Yes

lme4::sleepstudy

  • Source: Published dataset distributed with an R package
  • Licence: lme4 (GPL)
  • Reference: Belenky et al. (2003), J. Sleep Research 12; subject 308's Reaction and rows 25-26 set missing here (12 rows); the reference is the complete-case refit by the same packages the engine calls (a wiring check of the missing-data path)
QuantityCeleusIndependent computationPublished valueAgrees
Test statistic161.918161.918-Yes
p-value1.27852e-251.27852e-25-Yes
Denominator degrees of freedom for the first predictor150150-Yes
Number of observations168168-Yes

Validation report

References

  1. Laird, N. M., Ware, J. H. (1982). Random-effects models for longitudinal data. Biometrics 38: 963-974. doi:10.2307/2529876 doi:10.2307/2529876
  2. Bates, D., Machler, M., Bolker, B., Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software 67: 1-48. doi:10.18637/jss.v067.i01 doi:10.18637/jss.v067.i01