A {gtsummary} wrapper function that takes a gtsummary univariate regression table and adds appropriate cross tabs by exposure and outcome

add_crosstabs(x, wide = FALSE)

Arguments

x

Object with class tbl_uvregression from the gtsummary tbl_uvregression function or tbl_cmh from the epitabulate tbl_cmh function.

wide

TRUE/FALSE to specify whether would like to have the output in wide format. Results in four columns rather than two, but in a single row. This is only works for dichotomous variables (yes/no, TRUE/FALSE, male/female), others will be dropped with a warning message. (Default is FALSE)

Value

A modified gtsummary table object (same class as input — e.g. "tbl_uvregression" or "tbl_cmh") containing additional cross-tabulated counts of outcomes and exposures. The structure depends on regression type:

  • For logistic models: adds case and control counts.

  • For Poisson models without offsets: adds total and case counts per exposure group (risk ratios).

  • For Poisson models with offsets: adds total person-time and case counts per exposure group (incidence rate ratios).

  • When wide = TRUE, dichotomous variables are reshaped to wide format with separate columns for exposed/unexposed counts.

References

Inspired by Daniel Sjoberg, see gtsummary github repo