Fits multivariable regression models within each stratum and returns a unified wide table with one "Characteristic" column and, under bold spanners for each stratum, model N, "Adjusted <effect>", and "p-value".
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 report. 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.
- adjust_for
Optional character vector of adjustment variables. Quoted and bare names are accepted. This argument works the same way as in
multi_reg().- interaction
Optional character scalar specifying one interaction term using standard formula syntax, e.g.
"bmi*sex"- approach
One of
"logit","firth","logbinomial","poisson","linear","robpoisson", or"negbin"- format
One of
"flextable"(default) or"gt".- theme
Preset name (e.g.
"minimal","striped","clinical","shaded","jama") or primitivesc("plain","zebra","lines","labels_bold","compact","header_shaded")- 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_multi_reg", ...) with:
tableA
flextable(format ="flextable") orgt_tbl(format ="gt").table_displayWide data frame used to build the table.
per_stratumNamed list of per-stratum regression results.
modelsNamed list of fitted models by stratum.
model_summariesNamed list of model summaries by stratum.
variable_labelsNamed character vector of display labels used for exposure variables.
reg_checkNamed list of diagnostics by stratum.
by,levels,approach,format,sourceMetadata fields.
Details
If adjust_for = NULL, all exposures are included in one
multivariable model within each stratum. If adjust_for is supplied,
one adjusted model is fitted per exposure within each stratum.
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.
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")),
ht = factor(ht, levels = c(0, 1), labels = c("No", "Yes")),
ui = factor(ui, levels = c(0, 1), labels = c("No", "Yes")),
low = factor(low, levels = c(0, 1),
labels = c("Normal BW", "Low BW"))
)
stratified_multi <- stratified_multi_reg(
data = birthwt_data,
outcome = "low",
exposures = c("age", "lwt", "smoke", "ht"),
stratifier = "race",
approach = "logit",
format = "gt"
)
#> Running stratified multivariable regression by: race
#> > Stratum: race = White
#> > Stratum: race = Black
#> > Stratum: race = Other
stratified_adjusted <- stratified_multi_reg(
data = birthwt_data,
outcome = "low",
exposures = c("smoke", "ht", "ui"),
stratifier = "race",
adjust_for = c("age", "lwt"),
approach = "logit",
format = "gt"
)
#> Running stratified multivariable regression by: race
#> > Stratum: race = White
#> > Stratum: race = Black
#> > Stratum: race = Other