tab_model() is the pendant to plot_model(), however, instead of creating plots, tab_model() creates HTML-tables that will be displayed either in your IDE’s viewer-pane, in a web browser or in a knitr-markdown-document (like this vignette).
HTML is the only output-format, you can’t (directly) create a LaTex or PDF output from tab_model() and related table-functions. However, it is possible to easily export the tables into Microsoft Word or Libre Office Writer.
This vignette shows how to create table from regression models with tab_model(). There’s a dedicated vignette that demonstrate how to change the table layout and appearance with CSS.
Note! Due to the custom CSS, the layout of the table inside a knitr-document differs from the output in the viewer-pane and web browser!
# load package
library(sjPlot)
library(sjmisc)
library(sjlabelled)
# sample data
data("efc")
efc <- as_factor(efc, c161sex, c172code)First, we fit two linear models to demonstrate the tab_model()-function.
m1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
m2 <- lm(neg_c_7 ~ c160age + c12hour + c161sex + e17age, data = efc)The simplest way of producing the table output is by passing the fitted model as parameter. By default, estimates, confidence intervals (CI) and p-values (p) are reported. As summary, the numbers of observations as well as the R-squared values are shown.
tab_model(m1)| Total score BARTHEL INDEX | ||||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | CI | p | |||||
| (Intercept) | 87.15 | 77.96 – 96.34 | <0.001 | |||||
| carer’age | -0.21 | -0.35 – -0.07 | 0.004 | |||||
|
average number of hours of care per week |
-0.28 | -0.32 – -0.24 | <0.001 | |||||
| carer’s gender: Female | -0.39 | -4.49 – 3.71 | 0.850 | |||||
|
intermediate level of education |
1.37 | -3.12 – 5.85 | 0.550 | |||||
| high level of education | -1.64 | -7.22 – 3.93 | 0.564 | |||||
| Observations | 821 | |||||||
| R2 / adjusted R2 | 0.271 / 0.266 | |||||||
| mpg | ||||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | CI | p | |||||
| (Intercept) | 38.75 | 35.09 – 42.41 | <0.001 | |||||
| cyl | -0.94 | -2.07 – 0.19 | 0.098 | |||||
| hp | -0.02 | -0.04 – 0.01 | 0.140 | |||||
| wt | -3.17 | -4.68 – -1.65 | <0.001 | |||||
| Observations | 32 | |||||||
| R2 / adjusted R2 | 0.843 / 0.826 | |||||||
| barthtot | ||||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | CI | p | |||||
| (Intercept) | 87.15 | 77.96 – 96.34 | <0.001 | |||||
| c160age | -0.21 | -0.35 – -0.07 | 0.004 | |||||
| c12hour | -0.28 | -0.32 – -0.24 | <0.001 | |||||
| c161sex2 | -0.39 | -4.49 – 3.71 | 0.850 | |||||
| c172code2 | 1.37 | -3.12 – 5.85 | 0.550 | |||||
| c172code3 | -1.64 | -7.22 – 3.93 | 0.564 | |||||
| Observations | 821 | |||||||
| R2 / adjusted R2 | 0.271 / 0.266 | |||||||
| Total score BARTHEL INDEX |
Negative impact with 7 items |
|||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | CI | p | Estimates | CI | p | ||
| (Intercept) | 87.15 | 77.96 – 96.34 | <0.001 | 9.83 | 7.33 – 12.33 | <0.001 | ||
| carer’age | -0.21 | -0.35 – -0.07 | 0.004 | 0.01 | -0.01 – 0.03 | 0.359 | ||
|
average number of hours of care per week |
-0.28 | -0.32 – -0.24 | <0.001 | 0.02 | 0.01 – 0.02 | <0.001 | ||
| carer’s gender: Female | -0.39 | -4.49 – 3.71 | 0.850 | 0.43 | -0.15 – 1.01 | 0.147 | ||
|
intermediate level of education |
1.37 | -3.12 – 5.85 | 0.550 | |||||
| high level of education | -1.64 | -7.22 – 3.93 | 0.564 | |||||
| elder’age | 0.01 | -0.03 – 0.04 | 0.741 | |||||
| Observations | 821 | 879 | ||||||
| R2 / adjusted R2 | 0.271 / 0.266 | 0.067 / 0.063 | ||||||
| Services for elderly | neg c 7 d | |||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Incidence Rate Ratios | CI | p | Odds Ratios | CI | p | ||
| (Intercept) | 0.30 | 0.21 – 0.45 | <0.001 | 6.54 | 3.66 – 11.96 | <0.001 | ||
| carer’age | 1.01 | 1.01 – 1.02 | <0.001 | |||||
|
average number of hours of care per week |
1.00 | 1.00 – 1.00 | <0.001 | |||||
| carer’s gender: Female | 1.01 | 0.87 – 1.19 | 0.867 | 1.87 | 1.31 – 2.69 | 0.001 | ||
|
intermediate level of education |
1.47 | 1.21 – 1.79 | <0.001 | 1.23 | 0.84 – 1.82 | 0.288 | ||
| high level of education | 1.90 | 1.52 – 2.38 | <0.001 | 1.37 | 0.84 – 2.23 | 0.204 | ||
| Total score BARTHEL INDEX | 0.97 | 0.96 – 0.97 | <0.001 | |||||
| Observations | 840 | 815 | ||||||
| Cox & Snell’s R2 / Nagelkerke’s R2 | 0.083 / 0.106 | 0.184 / 0.247 | ||||||
| tot_sc_e | neg_c_7d | |||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Log-Mean | CI | p | Log-Odds | CI | p | ||
| (Intercept) | -1.19 | -1.58 – -0.80 | <0.001 | 1.88 | 1.30 – 2.48 | <0.001 | ||
| c160age | 0.01 | 0.01 – 0.02 | <0.001 | |||||
| c12hour | 0.00 | 0.00 – 0.00 | <0.001 | |||||
| c161sex2 | 0.01 | -0.15 – 0.18 | 0.867 | 0.63 | 0.27 – 0.99 | 0.001 | ||
| c172code2 | 0.39 | 0.19 – 0.58 | <0.001 | 0.21 | -0.18 – 0.60 | 0.288 | ||
| c172code3 | 0.64 | 0.42 – 0.87 | <0.001 | 0.31 | -0.17 – 0.80 | 0.204 | ||
| barthtot | -0.03 | -0.04 – -0.03 | <0.001 | |||||
| Observations | 840 | 815 | ||||||
| Cox & Snell’s R2 / Nagelkerke’s R2 | 0.083 / 0.106 | 0.184 / 0.247 | ||||||
| art | ||||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Incidence Rate Ratios | CI | p | |||||
| (Intercept) | 1.90 | 1.50 – 2.41 | <0.001 | |||||
| femWomen | 0.81 | 0.72 – 0.92 | 0.001 | |||||
| marMarried | 1.11 | 0.97 – 1.28 | 0.145 | |||||
| kid 5 | 0.87 | 0.79 – 0.95 | 0.003 | |||||
| phd | 0.99 | 0.94 – 1.06 | 0.842 | |||||
| ment | 1.02 | 1.01 – 1.02 | <0.001 | |||||
| Zero-Inflated Model | ||||||||
| (Intercept) | 0.56 | 0.21 – 1.52 | 0.257 | |||||
| femWomen | 1.12 | 0.64 – 1.93 | 0.695 | |||||
| marMarried | 0.70 | 0.38 – 1.31 | 0.265 | |||||
| kid 5 | 1.24 | 0.85 – 1.83 | 0.269 | |||||
| phd | 1.00 | 0.75 – 1.33 | 0.993 | |||||
| ment | 0.87 | 0.80 – 0.96 | 0.003 | |||||
| barthtot | tot_sc_e | art | ||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | p | Incidence Rate Ratios | p | Incidence Rate Ratios | p | ||
| (Intercept) | 87.15 | <0.001 | 0.30 | <0.001 | 1.90 | <0.001 | ||
| c160age | -0.21 | 0.004 | 1.01 | <0.001 | ||||
| c12hour | -0.28 | <0.001 | 1.00 | <0.001 | ||||
| c161sex2 | -0.39 | 0.850 | 1.01 | 0.867 | ||||
| c172code2 | 1.37 | 0.550 | 1.47 | <0.001 | ||||
| c172code3 | -1.64 | 0.564 | 1.90 | <0.001 | ||||
| femWomen | 0.81 | 0.001 | ||||||
| marMarried | 1.11 | 0.145 | ||||||
| kid5 | 0.87 | 0.003 | ||||||
| phd | 0.99 | 0.842 | ||||||
| ment | 1.02 | <0.001 | ||||||
| Zero-Inflated Model | ||||||||
| (Intercept) | 0.56 | 0.257 | ||||||
| femWomen | 1.12 | 0.695 | ||||||
| marMarried | 0.70 | 0.265 | ||||||
| kid5 | 1.24 | 0.269 | ||||||
| phd | 1.00 | 0.993 | ||||||
| ment | 0.87 | 0.003 | ||||||
| Observations | 821 | 840 | NA | |||||
| R2 / adjusted R2 | 0.271 / 0.266 | 0.083 / 0.106 | NA | |||||
| Total score BARTHEL INDEX | ||||||||
|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | std. Beta | standardized std. Error | CI | standardized CI | Statistic | p |
| (Intercept) | 87.15 | 4.68 | 77.96 – 96.34 | 18.62 | <0.001 | |||
| carer’age | -0.21 | 0.07 | -0.09 | 0.03 | -0.35 – -0.07 | -0.16 – -0.03 | -2.87 | 0.004 |
|
average number of hours of care per week |
-0.28 | 0.02 | -0.48 | 0.03 | -0.32 – -0.24 | -0.54 – -0.42 | -14.95 | <0.001 |
| carer’s gender: Female | -0.39 | 2.09 | -0.01 | 0.03 | -4.49 – 3.71 | -0.06 – 0.05 | -0.19 | 0.850 |
|
intermediate level of education |
1.37 | 2.28 | 0.02 | 0.04 | -3.12 – 5.85 | -0.05 – 0.10 | 0.60 | 0.550 |
| high level of education | -1.64 | 2.84 | -0.02 | 0.04 | -7.22 – 3.93 | -0.09 – 0.05 | -0.58 | 0.564 |
| Observations | 821 | |||||||
| R2 / adjusted R2 | 0.271 / 0.266 | |||||||
| tot_sc_e | neg_c_7d | |||||
|---|---|---|---|---|---|---|
| Predictors | Incidence Rate Ratios | Odds Ratios | ||||
| (Intercept) | 0.30 | 6.54 | ||||
| c160age | 1.01 | |||||
| c12hour | 1.00 | |||||
| c161sex2 | 1.01 | 1.87 | ||||
| c172code2 | 1.47 | 1.23 | ||||
| c172code3 | 1.90 | 1.37 | ||||
| barthtot | 0.97 | |||||
| Observations | 840 | 815 | ||||
| Cox & Snell’s R2 / Nagelkerke’s R2 | 0.083 / 0.106 | 0.184 / 0.247 | ||||
| Total score BARTHEL INDEX | ||||||
|---|---|---|---|---|---|---|
| Predictors | Estimates | p | ||||
| (Intercept) |
87.15 (77.96 – 96.34) |
<0.001 | ||||
| carer’age |
-0.21 (-0.35 – -0.07) |
0.004 | ||||
|
average number of hours of care per week |
-0.28 (-0.32 – -0.24) |
<0.001 | ||||
| carer’s gender: Female |
-0.39 (-4.49 – 3.71) |
0.850 | ||||
|
intermediate level of education |
1.37 (-3.12 – 5.85) |
0.550 | ||||
| high level of education |
-1.64 (-7.22 – 3.93) |
0.564 | ||||
| Observations | 821 | |||||
| R2 / adjusted R2 | 0.271 / 0.266 | |||||
| First Model | M2 | |||||
|---|---|---|---|---|---|---|
| Coeffcient | Estimates | Conf. Int (95%) | P-Value | Estimates | Conf. Int (95%) | P-Value |
| Intercept | 87.15 | 77.96 – 96.34 | <0.001 | 9.83 | 7.33 – 12.33 | <0.001 |
| Age (Carer) | -0.21 | -0.35 – -0.07 | 0.004 | 0.01 | -0.01 – 0.03 | 0.359 |
| Hours per Week | -0.28 | -0.32 – -0.24 | <0.001 | 0.02 | 0.01 – 0.02 | <0.001 |
| Gender (Carer) | -0.39 | -4.49 – 3.71 | 0.850 | 0.43 | -0.15 – 1.01 | 0.147 |
| Education: middle (Carer) | 1.37 | -3.12 – 5.85 | 0.550 | |||
| Education: high (Carer) | -1.64 | -7.22 – 3.93 | 0.564 | |||
| Age (Older Person) | 0.01 | -0.03 – 0.04 | 0.741 | |||
| Observations | 821 | 879 | ||||
| R2 / adjusted R2 | 0.271 / 0.266 | 0.067 / 0.063 | ||||
| Model1 | Model2 | Model3 | Model4 | |
|---|---|---|---|---|
| Predictors | Estimates | Estimates | Log-Mean | Log-Odds |
| Intercept | 87.15 | 9.83 | -1.19 | 1.88 |
| Age (Carer) | -0.21 | 0.01 | 0.01 | |
| Hours per Week | -0.28 | 0.02 | 0.00 | |
| Gender (Carer) | -0.39 | 0.43 | 0.01 | 0.63 |
| Education: middle (Carer) | 1.37 | 0.39 | 0.21 | |
| Education: high (Carer) | -1.64 | 0.64 | 0.31 | |
| Age (Older Person) | 0.01 | |||
| Barthel-Index | -0.03 | |||
| Observations | 821 | 879 | 840 | 815 |
| R2 / adjusted R2 | 0.271 / 0.266 | 0.067 / 0.063 | 0.083 / 0.106 | 0.184 / 0.247 |
| Total score BARTHEL INDEX | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| carer’age | -0.21 | -0.35 – -0.07 | 0.004 |
|
average number of hours of care per week |
-0.28 | -0.32 – -0.24 | <0.001 |
| Observations | 821 | ||
| R2 / adjusted R2 | 0.271 / 0.266 | ||
| Total score BARTHEL INDEX | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 87.15 | 77.96 – 96.34 | <0.001 |
| carer’age | -0.21 | -0.35 – -0.07 | 0.004 |
|
average number of hours of care per week |
-0.28 | -0.32 – -0.24 | <0.001 |
| high level of education | -1.64 | -7.22 – 3.93 | 0.564 |
| Observations | 821 | ||
| R2 / adjusted R2 | 0.271 / 0.266 | ||