Summary of Mixed Models as HTML Table

Daniel Lüdecke

2019-09-29

This vignette shows examples for using tab_model() to create HTML tables for mixed models. Basically, tab_model() behaves in a very similar way for mixed models as for other, simple regression models, as shown in this vignette.

# load required packages
library(sjPlot)
library(lme4)
library(nlme)
data("sleepstudy")
data("Orthodont")

Mixed models summaries as HTML table

Unlike tables for non-mixed models, tab_models() adds additional information on the random effects to the table output for mixed models. You can hide these information with show.icc = FALSE and show.re.var = FALSE. Furthermore, the R-squared values are marginal and conditional R-squared statistics, based on Nakagawa et al. 2017.

m1 <- lmer(distance ~ age + Sex + (1 | Subject), data = Orthodont)
m2 <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)

tab_model(m1, m2)
  distance Reaction
Predictors Estimates CI p Estimates CI p
(Intercept) 17.71 16.07 – 19.34 <0.001 251.41 238.03 – 264.78 <0.001
age 0.66 0.54 – 0.78 <0.001
Sex: Female -2.32 -3.81 – -0.83 0.002
Days 10.47 7.44 – 13.50 <0.001
Random Effects
σ2 2.05 654.94
τ00 3.27 Subject 611.90 Subject
τ11   35.08 Subject.Days
ρ01   0.07 Subject
ICC 0.61 0.72
N 27 Subject 18 Subject
Observations 108 180
Marginal R2 / Conditional R2 0.398 / 0.768 0.279 / 0.799

The marginal R-squared considers only the variance of the fixed effects, while the conditional R-squared takes both the fixed and random effects into account.

The p-value is a simple approximation, based on the t-statistics and using the normal distribution function. A more precise p-value can be computed using p.val = "kr". In this case, which only applies to linear mixed models, the computation of p-values is based on conditional F-tests with Kenward-Roger approximation for the degrees of freedom (using the using the pbkrtest-package). Note that here the computation is more time consuming and thus not used as default. You can also display the approximated degrees of freedom with show.df.

tab_model(m1, p.val = "kr", show.df = TRUE)
  distance
Predictors Estimates CI p df
(Intercept) 17.71 16.07 – 19.34 <0.001 99.35
age 0.66 0.54 – 0.78 <0.001 80.00
Sex: Female -2.32 -3.81 – -0.83 0.005 25.00
Random Effects
σ2 2.05
τ00 Subject 3.27
ICC 0.61
N Subject 27
Observations 108
Marginal R2 / Conditional R2 0.398 / 0.768

Generalized linear mixed models

tab_model() can also print and combine models with different link-functions.

data("efc")
efc$neg_c_7d <- ifelse(efc$neg_c_7 < median(efc$neg_c_7, na.rm = TRUE), 0, 1)
efc$cluster <- as.factor(efc$e15relat)
m3 <- glmer(
  neg_c_7d ~ c160age + c161sex + e42dep + (1 | cluster),
  data = efc, 
  family = binomial(link = "logit")
)

tab_model(m1, m3)
  distance neg c 7 d
Predictors Estimates CI p Odds Ratios CI p
(Intercept) 17.71 16.07 – 19.34 <0.001 0.02 0.01 – 0.05 <0.001
age 0.66 0.54 – 0.78 <0.001
Sex: Female -2.32 -3.81 – -0.83 0.002
carer’age 1.01 0.99 – 1.02 0.355
carer’s gender 1.83 1.30 – 2.59 0.001
elder’s dependency 2.37 1.99 – 2.81 <0.001
Random Effects
σ2 2.05 3.29
τ00 3.27 Subject 0.24 cluster
ICC 0.61 0.07
N 27 Subject 8 cluster
Observations 108 888
Marginal R2 / Conditional R2 0.398 / 0.768 0.181 / 0.237

More complex models

Finally, an example from the glmmTMB-package to show how easy it is to print zero-inflated generalized linear mixed models as HTML table.

library(glmmTMB)
data("Salamanders")
m4 <- glmmTMB(
  count ~ spp + mined + (1 | site),
  ziformula = ~ spp + mined, 
  family = truncated_poisson(link = "log"), 
  data = Salamanders
)

tab_model(m1, m3, m4, show.ci = FALSE)
#> Warning: mu of 2.5 is too close to zero, estimate of random effect variances may be unreliable.
  distance neg c 7 d count
Predictors Estimates p Odds Ratios p Incidence Rate Ratios p
(Intercept) 17.71 <0.001 0.02 <0.001 0.94 0.745
age 0.66 <0.001
Sex: Female -2.32 0.002
carer’age 1.01 0.355
carer’s gender 1.83 0.001
elder’s dependency 2.37 <0.001
spp: PR 0.59 0.062
spp: DM 1.25 0.121
spp: EC-A 0.82 0.331
spp: EC-L 1.91 <0.001
spp: DES-L 1.83 <0.001
spp: DF 1.05 0.765
mined: no 2.76 <0.001
Zero-Inflated Model
(Intercept) 5.79 <0.001
spp: PR 5.36 <0.001
spp: DM 0.65 0.223
spp: EC-A 3.02 0.003
spp: EC-L 0.65 0.223
spp: DES-L 0.51 0.056
spp: DF 0.65 0.223
mined: no 0.09 <0.001
Random Effects
σ2 2.05 3.29 0.10
τ00 3.27 Subject 0.24 cluster 0.05 site
ICC 0.61 0.07 0.34
N 27 Subject 8 cluster 23 site
Observations 108 888 644
Marginal R2 / Conditional R2 0.398 / 0.768 0.181 / 0.237 0.724 / 0.819

References

Nakagawa S, Johnson P, Schielzeth H (2017) The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisted and expanded. J. R. Soc. Interface 14. doi: 10.1098/rsif.2017.0213