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!

A simple HTML table from regression results

First, we fit two linear models to demonstrate the tab_model()-function.

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.

  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

Automatic labelling

As the sjPlot-packages features labelled data, the coefficients in the table are already labelled in this example. The name of the dependent variable(s) is used as main column header for each model. For non-labelled data, the coefficient names are shown.

  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

Turn off automatic labelling

To turn off automatic labelling, use auto.label = FALSE, or provide an empty character vector for pred.labels and dv.labels.

tab_model(m1, auto.label = FALSE)
  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

More than one model

tab_model() can print multiple models at once, which are then printed side-by-side. Identical coefficients are matched in a row.

tab_model(m1, m2)
  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

Generalized linear models

For generalized linear models, the ouput is slightly adapted. Instead of Estimates, the column is named Odds Ratios, Incidence Rate Ratios etc., depending on the model. The coefficients are in this case automatically converted (exponentiated). Furthermore, pseudo R-squared statistics are shown in the summary.

  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

Untransformed estimates on the linear scale

To plot the estimates on the linear scale, use transform = NULL.

tab_model(m3, m4, transform = NULL, auto.label = FALSE)
  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

More complex models

Other models, like hurdle- or zero-inflated models, also work with tab_model(). In this case, the zero inflation model is indicated in the table. Use show.zeroinf = FALSE to hide this part from the table.

  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

You can combine any model in one table.

tab_model(m1, m3, m5, auto.label = FALSE, show.ci = FALSE)
  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

Show or hide further columns

tab_model() has some argument that allow to show or hide specific columns from the output:

  • show.est to show/hide the column with model estimates.
  • show.ci to show/hide the column with confidence intervals.
  • show.se to show/hide the column with standard errors.
  • show.std to show/hide the column with standardized estimates (and their standard errors).
  • show.p to show/hide the column with p-values.
  • show.stat to show/hide the column with the coefficients’ test statistics.
  • show.df for linear mixed models, when p-values are based on degrees of freedom with Kenward-Rogers approximation, these degrees of freedom are shown.

Adding columns

In the following example, standard errors, standardized coefficients and test statistics are also shown.

tab_model(m1, show.se = TRUE, show.std = TRUE, show.stat = TRUE)
  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

Removing columns

In the following example, default columns are removed.

tab_model(m3, m4, show.ci = FALSE, show.p = FALSE, auto.label = FALSE)
  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

Collapsing columns

With collapse.ci and collapse.se, the columns for confidence intervals and standard errors can be collapsed into one column together with the estimates. Sometimes this table layout is required.

tab_model(m1, collapse.ci = TRUE)
  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

Defining own labels

There are different options to change the labels of the column headers or coefficients, e.g. with:

  • pred.labels to change the names of the coefficients in the Predictors column. Note that the length of pred.labels must exactly match the amount of predictors in the Predictor column.
  • dv.labels to change the names of the model columns, which are labelled with the variable labels / names from the dependent variables.
  • Further more, there are various string.*-arguments, to change the name of column headings.
  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

Automatic matching for named vectors

Another way to easily assign labels are named vectors. In this case, it doesn’t matter if pred.labels has more labels than coefficients in the model(s), or in which order the labels are passed to tab_model(). The only requirement is that the labels’ names equal the coefficients names as they appear in the summary()-output.

  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

Keep or remove coefficients from the table

Using the terms- or rm.terms-argument allows us to explicitly show or remove specific coefficients from the table output.

tab_model(m1, terms = c("c160age", "c12hour"))
  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

Note that the names of terms to keep or remove should match the coefficients names. For categorical predictors, one example would be:

tab_model(m1, rm.terms = c("c172code2", "c161sex2"))
  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

Site built with pkgdown.