Printing different models into a beautiful table

I know, this table looks quite strange, but… it demonstrates quite well the great flexibility of the tab_model() function from the sjPlot-package for printing regression models to a (HTML) table, mixing different specific parts for each model.

library(sjPlot)
library(brms)
library(glmmTMB)
library(MASS)
library(lme4)
data(efc)
efc$grp <- as.factor(efc$e15relat)
efc$cluster <- as.factor(efc$n4pstu)

m1 <- glmmTMB(
  count ~ spp + mined + (1 | site),
  zi =  ~ spp + mined,
  family = nbinom2,
  data = Salamanders
)
         
m2 <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)

m3 <-
  glmmTMB(
    SiblingNegotiation ~ FoodTreatment + ArrivalTime + SexParent + (1 | Nest),
    data = Owls,
    ziformula = ~ FoodTreatment + ArrivalTime,
    family = truncated_poisson()
  )

m4 <- brm(neg_c_7 ~ e42dep + c12hour + c172code, data = efc)

m5 <- lmer(neg_c_7 ~ e42dep + c12hour + c172code + (1 | grp) + (1 | cluster), data = efc)

The following table shows, from left to right:

  1. a negative binomial mixed-model with zero-inflated part, so we have a zero-inflated part and random effects.
  2. a proportional odds logistic regression model
  3. a truncated poisson mixed model with zero-inflation.
  4. a Bayesian linear regression model; unlike the other models, this model has no p-values, and instead of confidence intervals, two different high density intervals are shown
  5. a linear mixed models with two random intercepts, where p-values were computed with Kenward-Rogers-approximation for the df’s; here we have an additional column, df, which shows the degrees of freedom for each p-value, and the random effects have two tau00 values.

In order to better differentiate the model columns, I used an alternating color for each column.

tab_model(
  m1, m2, m3, m4, m5, 
  p.val = "kr", 
  show.zeroinf = T, 
  show.se = T, 
  show.df = T, 
  show.re.var = T,
  # to better distinguish the model columns
  CSS = list(
    modelcolumn1 = "background-color: #f0f0f0;", 
    modelcolumn3 = "background-color: #f0f0f0;", 
    modelcolumn5 = "background-color: #f0f0f0;"
  )
)
Predictors Incidence Rate Ratios std. Error CI p Odds Ratios std. Error CI p Incidence Rate Ratios std. Error CI p Estimates std. Error HDI (50%) HDI (95%) Estimates std. Error CI p df
(Intercept) 0.54 0.41 0.25 – 1.20 0.132 66.44 0.23 42.31 – 104.34 <0.001 6.77 0.66 5.69 – 7.85 <0.001 75.00
sppPR 0.38 0.64 0.11 – 1.35 0.134
sppDM 1.19 0.24 0.75 – 1.88 0.468
sppEC-A 0.68 0.34 0.35 – 1.33 0.258
sppEC-L 1.63 0.24 1.02 – 2.60 0.041
sppDES-L 1.80 0.23 1.15 – 2.82 0.010
sppDF 0.89 0.24 0.55 – 1.44 0.642
minedno 4.18 0.37 2.04 – 8.57 <0.001
InflMedium 1.76 0.10 1.44 – 2.16 <0.001
InflHigh 3.63 0.13 2.83 – 4.66 <0.001
TypeApartment 0.56 0.12 0.45 – 0.71 <0.001
TypeAtrium 0.69 0.16 0.51 – 0.94 0.018
TypeTerrace 0.34 0.15 0.25 – 0.45 <0.001
ContHigh 1.43 0.10 1.19 – 1.73 <0.001
(Intercept: Low|Medium) 0.61 0.12 0.48 – 0.78 <0.001
(Intercept: Medium|High) 2.00 0.13 1.56 – 2.55 <0.001
FoodTreatmentSatiated 0.81 0.04 0.75 – 0.87 <0.001
ArrivalTime 0.92 0.01 0.91 – 0.94 <0.001
SexParentMale 0.98 0.04 0.91 – 1.05 0.572
b_Intercept 6.92 0.56 6.52 – 7.27 5.87 – 8.04
b_e42dep 1.36 0.15 1.27 – 1.47 1.08 – 1.66
b_c12hour 0.01 0.00 0.01 – 0.01 0.00 – 0.01
b_c172code 0.31 0.21 0.14 – 0.42 -0.05 – 0.70
e42dep 1.33 0.16 1.07 – 1.59 <0.001 636.00
c12hour 0.01 0.00 0.00 – 0.01 0.021 551.00
c172code 0.32 0.20 -0.01 – 0.65 0.115 821.00
Zero-Inflated Model
(Intercept) 2.48 0.63 0.73 – 8.51 0.147 0.00 1.31 0.00 – 0.02 <0.001
sppPR 3.19 1.33 0.23 – 43.70 0.384
sppDM 0.39 0.80 0.08 – 1.88 0.241
sppEC-A 2.84 0.71 0.70 – 11.49 0.144
sppEC-L 0.57 0.73 0.14 – 2.37 0.439
sppDES-L 0.41 0.75 0.09 – 1.79 0.236
sppDF 0.08 2.18 0.00 – 5.68 0.244
minedno 0.08 0.60 0.02 – 0.25 <0.001
FoodTreatmentSatiated 4.33 0.21 2.89 – 6.49 <0.001
ArrivalTime 1.21 0.05 1.10 – 1.34 <0.001
Random Effects
σ2 2.29   1.00   12.80
τ00 0.14 (site)   0.06 (Nest)   0.26 (grp)
τ00         0.00 (cluster)
Observations 644 1681 599 834 825
Marginal R2 / Conditional R2 0.429 / 0.511 NA NA 0.156 / 0.020 0.141 / 0.158

Cool?

If you like, install from GitHub and try out tab_model()! Note that not all arguments are documented yet, as the function is still work in progress…

To-Do:

  • add column header for each “model column”"
  • show Random-Slope and Random-Slope-Intercept (co-)variances
  • show ICC for mixed models
  • ???