Learn R Programming

gtsummary (version 1.2.0)

tbl_regression: Display regression model results in table

Description

This function uses broom::tidy and broom.mixed::tidy to perform the initial model formatting. Review the tbl_regression vignette for detailed examples.

Usage

tbl_regression(x, label = NULL, exponentiate = FALSE, include = NULL,
  exclude = NULL, show_yesno = NULL, conf.level = NULL,
  intercept = FALSE, estimate_fun = NULL, pvalue_fun = NULL)

Arguments

x

Regression model object

label

List of formulas specifying variables labels, e.g. list("age" ~ "Age, yrs", "ptstage" ~ "Path T Stage")

exponentiate

Logical indicating whether to exponentiate the coefficient estimates. Default is FALSE.

include

Names of variables to include in output.

exclude

Names of variables to exclude from output.

show_yesno

By default yes/no categorical variables are printed on a single row, when the 'No' category is the reference group. To print both levels in the output table, include the variable name in the show_yesno vector, e.g. `show_yesno = c("var1", "var2")``

conf.level

Must be strictly greater than 0 and less than 1. Defaults to 0.95, which corresponds to a 95 percent confidence interval.

intercept

Logical argument indicating whether to include the intercept in the output. Default is FALSE

estimate_fun

Function to round and format coefficient estimates. Default is style_sigfig when the coefficients are not transformed, and style_ratio when the coefficients have been exponentiated.

pvalue_fun

Function to round and format p-values. Default is style_pvalue. The function must have a numeric vector input (the numeric, exact p-value), and return a string that is the rounded/formatted p-value (e.g. pvalue_fun = function(x) style_pvalue(x, digits = 2) or equivalently, purrr::partial(style_pvalue, digits = 2)).

Value

A tbl_regression object

Setting Defaults

If you prefer to consistently use a different function to format p-values or estimates, you can set options in the script or in the user- or project-level startup file, '.Rprofile'. The default confidence level can also be set.

  • options(gtsummary.pvalue_fun = new_function)

  • options(gtsummary.tbl_regression.estimate_fun = new_function)

  • options(gtsummary.conf.level = 0.90)

Example Output

Example 1

Example 2

Example 3

See Also

See tbl_regression vignette for detailed examples

Other tbl_regression tools: add_global_p.tbl_regression, add_nevent.tbl_regression, bold_italicize_labels_levels, bold_p.tbl_regression, bold_p.tbl_stack, inline_text.tbl_regression, modify_header, sort_p.tbl_regression, tbl_merge, tbl_stack

Examples

Run this code
# NOT RUN {
library(survival)
tbl_regression_ex1 <-
  coxph(Surv(ttdeath, death) ~ age + marker, trial) %>%
  tbl_regression(exponentiate = TRUE)

tbl_regression_ex2 <-
  glm(response ~ age + grade, trial, family = binomial(link = "logit")) %>%
  tbl_regression(exponentiate = TRUE)

library(lme4)
tbl_regression_ex3 <-
  glmer(am ~ hp + (1 | gear), mtcars, family = binomial) %>%
  tbl_regression(exponentiate = TRUE)
# }

Run the code above in your browser using DataLab