Estimates and CI for random effects
Dallak opened this issue · comments
Hi,
Thanks for the great package!
I'm wondering if this package has a function that extracts the estimates and CIs of random effects for different groups in cases like (1+A+B*C|subject).
Thanks in advance!
Currently, you either get what you see fromtab_model()
or plot_model(type = "re")
. However, sjPlot uses the parameters package to extract estimates, which can do that. So I might implement this in a future update as well.
For now, you can do following:
library(lme4)
#> Loading required package: Matrix
library(parameters)
m <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
model_parameters(m)
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | t(174) | p
#> ---------------------------------------------------------------------
#> (Intercept) | 251.41 | 6.82 | [237.94, 264.87] | 36.84 | < .001
#> Days | 10.47 | 1.55 | [ 7.42, 13.52] | 6.77 | < .001
#>
#> # Random Effects
#>
#> Parameter | Coefficient | SE | 95% CI
#> -------------------------------------------------------------------
#> SD (Intercept: Subject) | 24.74 | 5.84 | [15.58, 39.28]
#> SD (Days: Subject) | 5.92 | 1.25 | [ 3.92, 8.95]
#> Cor (Intercept~Days: Subject) | 0.07 | 0.32 | [-0.51, 0.60]
#> SD (Residual) | 25.59 | 1.51 | [22.80, 28.72]
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
model_parameters(m, group_level = TRUE)
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | t(174) | p
#> ---------------------------------------------------------------------
#> (Intercept) | 251.41 | 6.82 | [237.94, 264.87] | 36.84 | < .001
#> Days | 10.47 | 1.55 | [ 7.42, 13.52] | 6.77 | < .001
#>
#> # Random Effects: Subject
#>
#> Parameter | Coefficient | SE | 95% CI
#> ----------------------------------------------------------
#> (Intercept) [308] | 2.26 | 12.07 | [-21.40, 25.92]
#> (Intercept) [309] | -40.40 | 12.07 | [-64.06, -16.74]
#> (Intercept) [310] | -38.96 | 12.07 | [-62.62, -15.30]
#> (Intercept) [330] | 23.69 | 12.07 | [ 0.03, 47.35]
#> (Intercept) [331] | 22.26 | 12.07 | [ -1.40, 45.92]
#> (Intercept) [332] | 9.04 | 12.07 | [-14.62, 32.70]
#> (Intercept) [333] | 16.84 | 12.07 | [ -6.82, 40.50]
#> (Intercept) [334] | -7.23 | 12.07 | [-30.89, 16.43]
#> (Intercept) [335] | -0.33 | 12.07 | [-23.99, 23.32]
#> (Intercept) [337] | 34.89 | 12.07 | [ 11.23, 58.55]
#> (Intercept) [349] | -25.21 | 12.07 | [-48.87, -1.55]
#> (Intercept) [350] | -13.07 | 12.07 | [-36.73, 10.59]
#> (Intercept) [351] | 4.58 | 12.07 | [-19.08, 28.24]
#> (Intercept) [352] | 20.86 | 12.07 | [ -2.79, 44.52]
#> (Intercept) [369] | 3.28 | 12.07 | [-20.38, 26.93]
#> (Intercept) [370] | -25.61 | 12.07 | [-49.27, -1.95]
#> (Intercept) [371] | 0.81 | 12.07 | [-22.85, 24.47]
#> (Intercept) [372] | 12.31 | 12.07 | [-11.34, 35.97]
#> Days [308] | 9.20 | 2.30 | [ 4.68, 13.72]
#> Days [309] | -8.62 | 2.30 | [-13.14, -4.10]
#> Days [310] | -5.45 | 2.30 | [ -9.97, -0.93]
#> Days [330] | -4.81 | 2.30 | [ -9.33, -0.30]
#> Days [331] | -3.07 | 2.30 | [ -7.59, 1.45]
#> Days [332] | -0.27 | 2.30 | [ -4.79, 4.25]
#> Days [333] | -0.22 | 2.30 | [ -4.74, 4.29]
#> Days [334] | 1.07 | 2.30 | [ -3.44, 5.59]
#> Days [335] | -10.75 | 2.30 | [-15.27, -6.23]
#> Days [337] | 8.63 | 2.30 | [ 4.11, 13.15]
#> Days [349] | 1.17 | 2.30 | [ -3.34, 5.69]
#> Days [350] | 6.61 | 2.30 | [ 2.10, 11.13]
#> Days [351] | -3.02 | 2.30 | [ -7.53, 1.50]
#> Days [352] | 3.54 | 2.30 | [ -0.98, 8.05]
#> Days [369] | 0.87 | 2.30 | [ -3.65, 5.39]
#> Days [370] | 4.82 | 2.30 | [ 0.31, 9.34]
#> Days [371] | -0.99 | 2.30 | [ -5.51, 3.53]
#> Days [372] | 1.28 | 2.30 | [ -3.23, 5.80]
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
Created on 2022-04-19 by the reprex package (v2.0.1)
Thank you!
This is what I am looking for. I'll go through parameter
and see what other options it has.
Many thanks again!