Fit univariable regression models within each level of a stratifier and combine the results into a stratified table rendered with gt or flextable.
Arguments
- data
A data frame containing the variables.
- outcome
Character scalar; name of the outcome variable. Quoted and bare names are accepted.
- exposures
Character vector of exposure variables to model. Quoted names are recommended in scripts, and bare names are also accepted.
- stratifier
Character scalar; name of the stratifying variable. Quoted and bare names are accepted.
- approach
Modeling approach. One of
"logit","firth","logbinomial","poisson","robpoisson","linear", or"negbin".- format
Output table format; one of
"flextable"(default) or"gt".- theme
Table styling preset or theme primitives.
- show_ref
Logical; if
TRUE(default), display reference-category rows as"Ref.". IfFALSE, hide reference rows; a message reminds users to useshow_ref = TRUEwhen reference rows are needed.
Value
A list of class
c("gtregression", "stratified_uni_reg", ...) with elements:
tableA rendered
gt_tblorflextable.table_displayDisplay-ready wide stratified results.
per_stratumList of complete
uni_reg()results by stratum.modelsList of fitted model objects by stratum.
model_summariesList of model summaries by stratum.
variable_labelsNamed character vector of display labels used for exposure variables.
reg_checkRegression diagnostics by stratum.
byThe stratifier variable.
levelsStrata included in the analysis.
approachThe regression approach used.
formatThe output format used.
sourceFunction identifier (
"stratified_uni_reg").
Details
If exposure variables have a "label" attribute, for example from
labelled::var_label(), those labels are used automatically in the
displayed table. Internal matching still uses the original column names.
Accessors
$tableRendered stratified regression table.
$table_displayWide display data used to build the table.
$per_stratumFull
uni_reg()result objects by stratum.$modelsList of fitted model objects for each stratum.
$model_summariesList of model summaries.
$reg_checkDiagnostic check results (when applicable).
Examples
birthwt_data <- data_birthwt |>
transform(
race = factor(race, levels = c(1, 2, 3),
labels = c("White", "Black", "Other")),
smoke = factor(smoke, levels = c(0, 1), labels = c("No", "Yes")),
low = factor(low, levels = c(0, 1),
labels = c("Normal BW", "Low BW"))
)
stratified_uni <- stratified_uni_reg(
data = birthwt_data,
outcome = "low",
exposures = c("age", "lwt", "smoke"),
stratifier = "race",
approach = "logit",
format = "gt"
)
#> Running stratified univariate regression by: race
#> > Stratum: race = White
#> > Stratum: race = Black
#> > Stratum: race = Other
stratified_uni$table
Abbreviations: OR = Odds Ratio; CI = Confidence Interval.
Ref. = reference category.