tab_bayes.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(sjmisc)
library(brms)
# load sample datasets
data("efc")
efc <- to_factor(efc, e42dep, c172code, c161sex, e15relat)
zinb <- read.csv("http://stats.idre.ucla.edu/stat/data/fish.csv")
# fit two sample models
m1 <- brm(
bf(count ~ child + camper + (1 | persons),
zi ~ child + camper),
data = zinb,
family = zero_inflated_poisson(),
cores = 4,
iter = 1000
)
f1 <- bf(neg_c_7 ~ e42dep + c12hour + c172code + (1 |ID| e15relat))
f2 <- bf(c12hour ~ c172code + (1 |ID| e15relat))
m2 <- brm(
f1 + f2 + set_rescor(FALSE),
data = efc,
cores = 4,
iter = 1000
)
For Bayesian regression models, some of the differences to the table output from simple models or mixed models of tab_models()
are the use of Highest Density Intervals instead of confidence intervals, the Bayes-R-squared values, and a different “point estimate” (which is, by default, the median from the posterior draws).
tab_model(m1)
count | |||
---|---|---|---|
Predictors | Incidence Rate Ratios | HDI (50%) | HDI (95%) |
Intercept | 3.14 | 1.75 – 5.69 | 0.27 – 31.18 |
child | 0.31 | 0.29 – 0.33 | 0.26 – 0.37 |
camper | 2.10 | 1.95 – 2.21 | 1.75 – 2.56 |
Zero-Inflated Model | |||
Intercept | 0.53 | 0.42 – 0.66 | 0.28 – 1.04 |
child | 3.78 | 2.93 – 4.32 | 2.27 – 7.21 |
camper | 0.50 | 0.39 – 0.64 | 0.24 – 1.12 |
Random Effects | |||
σ2 | 1.00 | ||
τ00persons | 5.35 | ||
ICC persons | 0.73 | ||
Observations | 250 | ||
Bayes R2 / Standard Error | 0.185 / 0.028 |
For multivariate response models, like mediator-analysis-models, it is recommended to print just one model in the table, as each regression is displayed as own “model” in the output.
tab_model(m2)
average number of hours of care per week |
Negative impact with 7 items |
|||||
---|---|---|---|---|---|---|
Predictors | Estimates | HDI (50%) | HDI (95%) | Estimates | HDI (50%) | HDI (95%) |
Intercept | 35.85 | 30.05 – 41.87 | 19.63 – 55.07 | 8.72 | 8.36 – 9.13 | 7.55 – 9.78 |
intermediate level of education |
-0.97 | -3.74 – 1.90 | -9.39 – 6.34 | 0.19 | 0.04 – 0.46 | -0.42 – 0.86 |
high level of education | -7.68 | -11.80 – -4.73 | -18.21 – 2.11 | 0.70 | 0.45 – 0.97 | -0.05 – 1.54 |
slightly dependent | 1.09 | 0.79 – 1.46 | 0.11 – 2.05 | |||
moderately dependent | 2.30 | 1.90 – 2.55 | 1.34 – 3.24 | |||
severely dependent | 3.87 | 3.61 – 4.33 | 2.90 – 4.92 | |||
average number of hours of care per week |
0.01 | 0.00 – 0.01 | 0.00 – 0.01 | |||
Random Effects | ||||||
σ2 | 12.82 | |||||
τ00e15relat | 0.51 | |||||
ICC e15relat | 0.04 | |||||
Observations | 834 | |||||
Bayes R2 / Standard Error | 0.170 / 0.167 |
To show just one HDI-column, use show.hdi50 = FALSE
.
tab_model(m2, show.hdi50 = FALSE)
average number of hours of care per week |
Negative impact with 7 items |
|||
---|---|---|---|---|
Predictors | Estimates | HDI (95%) | Estimates | HDI (95%) |
Intercept | 35.85 | 19.63 – 55.07 | 8.72 | 7.55 – 9.78 |
intermediate level of education |
-0.97 | -9.39 – 6.34 | 0.19 | -0.42 – 0.86 |
high level of education | -7.68 | -18.21 – 2.11 | 0.70 | -0.05 – 1.54 |
slightly dependent | 1.09 | 0.11 – 2.05 | ||
moderately dependent | 2.30 | 1.34 – 3.24 | ||
severely dependent | 3.87 | 2.90 – 4.92 | ||
average number of hours of care per week |
0.01 | 0.00 – 0.01 | ||
Random Effects | ||||
σ2 | 12.82 | |||
τ00e15relat | 0.51 | |||
ICC e15relat | 0.04 | |||
Observations | 834 | |||
Bayes R2 / Standard Error | 0.170 / 0.167 |
When both multivariate and univariate response models are displayed in one table, a column Response is added for the multivariate response model, to indicate the different outcomes.
tab_model(m1, m2, show.hdi50 = F)
count |
Negative impact with 7 items |
||||
---|---|---|---|---|---|
Predictors | Incidence Rate Ratios | HDI (95%) | Estimates | HDI (95%) | Response |
Intercept | 3.14 | 0.27 – 31.18 | 8.72 | 7.55 – 9.78 | negc7 |
Intercept | 3.14 | 0.27 – 31.18 | 35.85 | 19.63 – 55.07 | c12hour |
child | 0.31 | 0.26 – 0.37 | |||
camper | 2.10 | 1.75 – 2.56 | |||
slightly dependent | 1.09 | 0.11 – 2.05 | negc7 | ||
moderately dependent | 2.30 | 1.34 – 3.24 | negc7 | ||
severely dependent | 3.87 | 2.90 – 4.92 | negc7 | ||
average number of hours of care per week |
0.01 | 0.00 – 0.01 | negc7 | ||
intermediate level of education |
0.19 | -0.42 – 0.86 | negc7 | ||
high level of education | 0.70 | -0.05 – 1.54 | negc7 | ||
intermediate level of education |
-0.97 | -9.39 – 6.34 | c12hour | ||
high level of education | -7.68 | -18.21 – 2.11 | c12hour | ||
Zero-Inflated Model | |||||
Intercept | 0.53 | 0.28 – 1.04 | |||
child | 3.78 | 2.27 – 7.21 | |||
camper | 0.50 | 0.24 – 1.12 | |||
Random Effects | |||||
σ2 | 1.00 | 12.82 | |||
τ00 | 5.35 persons | 0.51 e15relat | |||
ICC | 0.73 persons | 0.04 e15relat | |||
Observations | 250 | 834 | |||
Bayes R2 / Standard Error | 0.185 / 0.028 | 0.170 / 0.167 |