The lmer
function in lme4
does provide estimates of the variance of the varying slopes/intercepts, both on the variance and the standard deviation scales.
> library(lme4)
Loading required package: Matrix
Loading required package: Rcpp
> m <- lmer(Reaction ~ Days + (Days|Subject),sleepstudy)
> m
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days | Subject)
Data: sleepstudy
REML criterion at convergence: 1743.628
Random effects:
Groups Name Std.Dev. Corr
Subject (Intercept) 24.740
Days 5.922 0.07
Residual 25.592
Number of obs: 180, groups: Subject, 18
Fixed Effects:
(Intercept) Days
251.41 10.47
> summary(m)
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days | Subject)
Data: sleepstudy
REML criterion at convergence: 1743.6
Scaled residuals:
Min 1Q Median 3Q Max
-3.9536 -0.4634 0.0231 0.4634 5.1793
Random effects:
Groups Name Variance Std.Dev. Corr
Subject (Intercept) 612.09 24.740
Days 35.07 5.922 0.07
Residual 654.94 25.592
Number of obs: 180, groups: Subject, 18
Fixed effects:
Estimate Std. Error t value
(Intercept) 251.405 6.825 36.84
Days 10.467 1.546 6.77
Correlation of Fixed Effects:
(Intr)
Days -0.138
As part of the REML or ML calculations, the BLUPs (more generally the conditional modes) are also computed. You can extract them with ranef()
:
> ranef(m)
$Subject
(Intercept) Days
308 2.2585637 9.1989722
309 -40.3985802 -8.6197026
310 -38.9602496 -5.4488792
330 23.6905025 -4.8143320
331 22.2602062 -3.0698952
332 9.0395271 -0.2721709
333 16.8404333 -0.2236248
334 -7.2325803 1.0745763
335 -0.3336936 -10.7521594
337 34.8903534 8.6282835
349 -25.2101138 1.1734148
350 -13.0699598 6.6142055
351 4.5778364 -3.0152574
352 20.8635944 3.5360130
369 3.2754532 0.8722166
370 -25.6128737 4.8224653
371 0.8070401 -0.9881551
372 12.3145406 1.2840295
lmer()
is the function, the package is calledlme4
. $\endgroup$confint()
gives confidence intervals for the variance components (as well as the fixed effects). $\endgroup$brms
, might be the better tool. $\endgroup$