Fits one regression model per variable and stacks the results in a single
table. With y the outcome is fixed and each column of data in
include is the predictor in turn; with x the predictor is fixed and
each column is the outcome in turn. Each model is summarized with
tbl_regression(), so every argument of that function applies.
Usage
tbl_uvregression(
data,
y = NULL,
x = NULL,
method,
method.args = list(),
exponentiate = FALSE,
label = NULL,
include = everything(),
tidy_fun = NULL,
hide_n = FALSE,
show_single_row = NULL,
conf.level = 0.95,
estimate_fun = ifelse(exponentiate, label_style_ratio(), label_style_sigfig()),
pvalue_fun = label_style_pvalue(digits = 1),
formula = "{y} ~ {x}",
add_estimate_to_reference_rows = FALSE,
conf.int = TRUE,
...
)Arguments
- data
(
data.frame)
A data frame.- y, x
(
stringor bare column name)
The outcome (y) or the predictor (x) used in every model. Exactly one of the two must be given. Either can be an expression that is not a column, e.g.y = survival::Surv(ttdeath, death), passed as a string.- method
(
functionorstring)
The model function, e.g.lm,glm,"glm"orsurvival::coxph.- method.args
(named
list)
Extra arguments formethod, e.g.list(family = binomial).- exponentiate
(
scalar logical)
Whether to exponentiate the coefficient estimates and their confidence limits. Default isFALSE.- label
(formula-list)
Variable labels, e.g.list(age ~ "Age, years"). The default for each variable is itslabelattribute in the model data, or the variable name when there is none.- include
(selector)
Columns ofdatato fit a model for. Columns named inx,yorformulaare left out. Default iseverything().- tidy_fun
(
function)
A tidier with the signature ofbroom::tidy(),function(x, conf.int, conf.level, exponentiate), returning a data frame with atermcolumn andestimate,std.error,statistic,p.value,conf.lowandconf.highcolumns. Default isNULL, which uses the built-in tidier forlm,glmandcoxphmodels andbroom::tidy()for anything else.- hide_n
(
scalar logical)
Whether to leave out theNcolumn. Default isFALSE.- show_single_row
(selector)
Dichotomous variables to show on a single row (the row of the non-reference level, labelled with the variable label) instead of a label row, a reference row and a level row. Default isNULL.- conf.level
(
scalar numeric)
Confidence level of the interval. Default is0.95.- estimate_fun
(
function)
Function that formats the estimate and the confidence limits. Default islabel_style_sigfig()whenexponentiate = FALSEandlabel_style_ratio()when it isTRUE.- pvalue_fun
(
function)
Function that formats p-values. Default islabel_style_pvalue(digits = 1).- formula
(
string)
Template of the model formula.{y}stands for the outcome and{x}for the predictor; both must appear exactly once, on their side of the~. Default is"{y} ~ {x}"; use e.g."{y} ~ {x} + age"to adjust every model for age.- add_estimate_to_reference_rows
(
scalar logical)
Whether to show the reference estimate (0, or1when exponentiated) on reference rows. Default isFALSE.- conf.int
(
scalar logical)
Whether to compute and show the confidence interval. Default isTRUE.- ...
Passed to
tbl_regression().
Value
A tbl_uvregression object, an ltsummary object
whose tbls element holds the tbl_regression table of each model. The
table is built with tbl_stack()'s machinery, so a hidden tbl_id1
column of table_body records which model each row came from.
Why this is not an S3 generic
gtsummary's tbl_regression() is a generic with a default method. When
both packages are attached, a method named tbl_regression.default in
ltsummary would be found by gtsummary's generic as well, because R looks
along the search path before the generic's own method registry. ltsummary
therefore exposes one plain function; model classes without a built-in
tidier are supported through tidy_fun.
See also
The tbl_regression() tutorial for the two forms side by side.
Other regression tables:
add_glance_table(),
add_global_p(),
add_n_regression,
add_nevent(),
add_significance_stars(),
add_vif(),
combine_terms(),
glance_fun_s3(),
global_pvalue_fun(),
tbl_regression()
Other table builders:
tbl_continuous(),
tbl_cross(),
tbl_custom_summary(),
tbl_likert(),
tbl_merge(),
tbl_regression(),
tbl_stack(),
tbl_strata(),
tbl_strata_nested_stack(),
tbl_summary(),
tbl_survfit(),
tbl_wide_summary()
Examples
# Example 1 ----------------------------------
# a logistic model for each predictor
trial |>
tbl_uvregression(
y = response,
include = c(age, grade, trt),
method = glm,
method.args = list(family = binomial),
exponentiate = TRUE
)
# Example 2 ----------------------------------
# a linear model for each outcome, with the predictor on a single row
trial |>
tbl_uvregression(
x = trt,
include = c(age, marker),
method = lm,
show_single_row = trt
)