Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Mixed models, REML and dream

When a study has several samples per donor (two conditions, several tissues, a time course), the samples of a donor are correlated. A fixed effect per donor removes that correlation, but it also absorbs every variable that is constant within a donor, such as disease status or sex, which then cannot be tested. A random intercept per donor models the correlation instead and keeps donor-level variables testable. dream applies this to gene expression Hoffman & Roussos, 2021, and dreamlet to the pseudobulk profiles of every cell type Hoffman et al., 2026.

The model

Every gene is fitted with the same model (lme4’s notation (1 | donor); Bates et al. (2015)):

y=Xβ+Z1b1+⋯+ZKbK+e,bk∼N(0,σk2I),e∼N(0,σ2W−1),y = X\beta + Z_1 b_1 + \dots + Z_K b_K + e, \qquad b_k \sim N(0, \sigma_k^2 I), \qquad e \sim N(0, \sigma^2 W^{-1}),

where XX holds the fixed effects, ZkZ_k assigns each sample to a level of the kk-th grouping factor (one random intercept per level), and WW holds the gene’s precision weights. Grouping factors may be crossed, (1 | donor) + (1 | batch), or nested, (1 | donor/sample). Random slopes are not implemented yet.

REML

fit_mixed_model estimates the variance components by restricted maximum likelihood Patterson & Thompson, 1971, as lme4’s lmer does, into a MixedModelFit. With θk=σk/σ\theta_k = \sigma_k / \sigma and V=W−1+∑kθk2ZkZk′V = W^{-1} + \sum_k \theta_k^2 Z_k Z_k', the fixed effects and σ2\sigma^2 are profiled out, and the criterion minimized is lme4’s profiled REML deviance

log⁡det⁡V+log⁡det⁡(X′V−1X)+(n−p)(1+log⁡2πr2n−p),\log\det V + \log\det(X' V^{-1} X) + (n - p)\left(1 + \log\frac{2\pi r^2}{n - p}\right),

with r2=(y−Xβ^)′V−1(y−Xβ^)r^2 = (y - X\hat\beta)' V^{-1} (y - X\hat\beta). Newton’s method minimizes it with exact derivatives Harville, 1977; a variance component whose estimate is zero is held exactly at zero, the boundary that lme4 reports as a singular fit. Random effects are predicted by their best linear unbiased predictors Henderson, 1975. method="ml" maximizes the likelihood instead.

Satterthwaite’s degrees of freedom

The t-statistic of a contrast cc of the fixed effects is c′β^/c′Ccc'\hat\beta / \sqrt{c' C c}, with CC the covariance matrix of the estimates. Its distribution is approximated by a t distribution with Satterthwaite’s degrees of freedom Satterthwaite, 1946Giesbrecht & Burns, 1985,

ν=2v2g′Ag,v=c′Cc,\nu = \frac{2 v^2}{g' A g}, \qquad v = c' C c,

where gg holds the derivatives of vv with respect to the variance parameters and AA is their asymptotic covariance matrix. fixed_effect_tests gives them in FixedEffectTests, computed as lmerTest does Kuznetsova et al., 2017, with exact derivatives where lmerTest takes numerical ones. With every component at zero, ν=n−p\nu = n - p, the degrees of freedom of the fixed-effects model.

dream

dream is limma-voom with the mixed model in place of the linear model:

  1. voom_with_dream_weights: voom’s precision weights, from the mean-variance trend of the mixed model of every gene, fitted by maximum likelihood, read at the fitted values with the predicted random effects.

  2. fit_mixed_model by REML with those weights, and fixed_effect_tests.

  3. moderated_fixed_effect_tests: empirical Bayes moderation of each gene’s residual variance on the approximate residual degrees of freedom of the mixed model, tr⁡((I−H)′(I−H))\operatorname{tr}((I - H)'(I - H)) for its hat matrix HH; the moderated t-statistic has Satterthwaite’s degrees of freedom plus the prior’s, and the result (ModeratedFixedEffectTests) adds a z-statistic with the same p-value, so that tests on different degrees of freedom compare.

dream_voom runs these steps on every cell type of a cube. As variancePartition does, it moderates the residual variance of an observation of each gene’s average weight, which keeps the mean-variance trend that voom’s weights remove; trend=True lets the prior follow it.

Not yet implemented

Kenward-Roger’s degrees of freedom (dream’s default for 20 samples or fewer), F-tests of several contrasts at once, random slopes and variance partitioning Hoffman & Schadt, 2016 are planned. A gene that the fixed and random effects reproduce exactly has no REML estimate; it is left unfitted rather than given a variance of zero.

References
  1. Hoffman, G. E., & Roussos, P. (2021). Dream: powerful differential expression analysis for repeated measures designs. Bioinformatics, 37(2), 192–201. 10.1093/bioinformatics/btaa687
  2. Hoffman, G. E., Lee, D., Bendl, J., Prashant, N. M., Hong, A., Casey, C., Alvia, M., Shao, Z., Argyriou, S., Therrien, K., Venkatesh, S., Voloudakis, G., Haroutunian, V., Fullard, J. F., & Roussos, P. (2026). Efficient differential expression analysis of large-scale single-cell transcriptomics data using Dreamlet. Nature Communications, 17(1), 9597. 10.1038/s41467-026-75680-8
  3. Bates, D., Mächler, M., Bolker, B., & Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1–48. 10.18637/jss.v067.i01
  4. Patterson, H. D., & Thompson, R. (1971). Recovery of inter-block information when block sizes are unequal. Biometrika, 58(3), 545–554. 10.1093/biomet/58.3.545
  5. Harville, D. A. (1977). Maximum likelihood approaches to variance component estimation and to related problems. Journal of the American Statistical Association, 72(358), 320–338. 10.1080/01621459.1977.10480998
  6. Henderson, C. R. (1975). Best linear unbiased estimation and prediction under a selection model. Biometrics, 31(2), 423–447. 10.2307/2529430
  7. Satterthwaite, F. E. (1946). An approximate distribution of estimates of variance components. Biometrics Bulletin, 2(6), 110–114. 10.2307/3002019
  8. Giesbrecht, F. G., & Burns, J. C. (1985). Two-stage analysis based on a mixed model: large-sample asymptotic theory and small-sample simulation results. Biometrics, 41(2), 477–486. 10.2307/2530872
  9. Kuznetsova, A., Brockhoff, P. B., & Christensen, R. H. B. (2017). lmerTest package: tests in linear mixed effects models. Journal of Statistical Software, 82(13), 1–26. 10.18637/jss.v082.i13
  10. Hoffman, G. E., & Schadt, E. E. (2016). variancePartition: interpreting drivers of variation in complex gene expression studies. BMC Bioinformatics, 17(1), 483. 10.1186/s12859-016-1323-z