tab_mixed.Rmd
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")
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)
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)
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)
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)
By default, the ICC for nested or cross-classified models only reports the proportion of variance explained for each grouping level. Use show.adj.icc = TRUE
to calculate the adjusted ICC, which takes all sources of uncertainty (of all random effects) into account.
If random effects are not nested and not cross-classified, the adjusted and unadjusted ICC are identical (see m1
in table below).
set.seed(2)
sleepstudy$mygrp <- sample(1:30, size = 180, replace = TRUE)
m5 <- lmer(Reaction ~ Days + (1 | mygrp) + (1 | Subject), sleepstudy)
tab_model(m1, m5, show.ci = FALSE, show.adj.icc = TRUE)