vignettes/summarize_model.Rmd
summarize_model.Rmd
This is pretty printing of results of a mixed model. Correlations of random and fixed effects are turned off by default, as the focus of interest is usually the variance components and fixed effects themselves. 95% confidence intervals are provided by default.
library(lme4)
library(glmmTMB)
library(nlme)
library(brms)
library(mgcv)
lmer_model <-
lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
lme_model <-
lme(Reaction ~ Days, random = ~ 1 + Days | Subject, data = sleepstudy)
tmb_model <-
glmmTMB(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
# brms_model <-
# brm(Reaction ~ Days + (1 + Days | Subject),
# data = sleepstudy,
# cores = 4,
# refresh = -1,
# verbose = FALSE
# )
# this is akin to (1 | Subject) + (0 + Days | Subject) in lme4
mgcv_model <-
gam(
Reaction ~ Days +
s(Subject, bs = 're') +
s(Days, Subject, bs = 're'),
data = lme4::sleepstudy,
method = 'REML'
)
library(mixedup)
summarize_model(lmer_model)
Computing profile confidence intervals ...
:
Variance Components.5 SD_97.5 Var_prop
Group Effect Variance SD SD_2612.10 24.74 14.38 37.72 0.47
Subject Intercept 35.07 5.92 3.80 8.75 0.03
Subject Days 654.94 25.59 22.90 28.86 0.50
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE t P_value Lower_2251.41 6.82 36.84 0.00 238.03 264.78
Intercept 10.47 1.55 6.77 0.00 7.44 13.50
Days
summarize_model(lme_model)
:
Variance Components.5 SD_97.5 Var_prop
Group Effect Variance SD SD_2612.08 24.74 15.52 39.44 0.47
Subject Intercept 35.07 5.92 3.90 8.98 0.03
Subject Days NA 654.94 25.59 22.80 28.73 0.50
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE Z P_value Lower_2251.41 6.82 36.84 0.00 237.93 264.88
Intercept 10.47 1.55 6.77 0.00 7.41 13.52
Days
summarize_model(tmb_model)
:
Variance Components.5 SD_97.5 Var_prop
Group Effect Variance SD SD_2565.52 23.78 15.02 37.66 0.45
Subject Intercept 32.68 5.72 3.81 8.59 0.03
Subject Days NA 654.94 25.59 NA NA 0.52
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE Z P_value Lower_2251.41 6.63 37.91 0.00 238.41 264.40
Intercept 10.47 1.50 6.97 0.00 7.52 13.41
Days
summarize_model(brms_model)
:
Variance Components.5 SD_97.5 Var_prop
Group Effect Variance SD SD_2792.95 28.16 15.85 46.34 0.53
Subject Intercept 42.20 6.50 4.33 9.28 0.03
Subject Days NA 669.47 25.87 22.46 29.57 0.44
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE Lower_2250.41 7.73 234.64 265.29
Intercept 10.48 1.70 6.96 13.54
Days
summarize_model(mgcv_model)
:
Variance Components.5 SD_97.5 Var_prop
Group Effect Variance SD SD_2627.57 25.05 16.09 39.02 0.48
Subject Intercept 35.86 5.99 4.03 8.91 0.03
Subject Days NA 653.58 25.57 22.79 28.68 0.50
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE t P_value Lower_2251.41 6.89 36.51 0.00 237.80 265.01
Intercept 10.47 1.56 6.71 0.00 7.39 13.55 Days
summarize_model(
lmer_model,ci = FALSE,
cor_re = TRUE,
cor_fe = TRUE,
digits = 3
)
:
Variance Components
Group Effect Variance SD Var_prop612.100 24.741 0.470
Subject Intercept 35.072 5.922 0.027
Subject Days 654.940 25.592 0.503
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE t P_value Lower_2251.405 6.825 36.838 0.000 238.029 264.781
Intercept 10.467 1.546 6.771 0.000 7.438 13.497
Days
summarise_model(lmer_model, ci = FALSE)
:
Variance Components
Group Effect Variance SD Var_prop612.10 24.74 0.47
Subject Intercept 35.07 5.92 0.03
Subject Days 654.94 25.59 0.50
Residual
:
Fixed Effects.5 Upper_97.5
Term Value SE t P_value Lower_2251.41 6.82 36.84 0.00 238.03 264.78
Intercept 10.47 1.55 6.77 0.00 7.44 13.50 Days
Often a model estimated by lme4 needs a bit of help for convergence. At present this function only works for lme4, but then, that’s mostly where you’re going to have the problem. This function will start with your current model and run it long enough to the point that if you still have problems, you probably really have data or model issues, and not just an estimation problem. See this for details.
# for some reason this example apparently only works interactively, not when knit
= sleepstudy
ss2 $Days = ss2$Days * 10
ss2
<- lmer(
lmer_not_converged ~ Days + (Days|Subject),
Reaction data = ss2
)
# lmer_not_converged
<- converge_it(lmer_not_converged) # final result is a converged model
lmer_converged
lmer_converged'lmerMod']
Linear mixed model fit by REML [: Reaction ~ Days + (Days | Subject)
Formula: ss2
Data: 1748.233
REML criterion at convergence:
Random effects
Groups Name Std.Dev. CorrSubject (Intercept) 24.7401
0.5922 0.07
Days 25.5918
Residual : 180, groups: Subject, 18
Number of obs:
Fixed Effects
(Intercept) Days 251.405 1.047