Skip to contents

Fit univariable regression models within each level of a stratifier and combine the results into a stratified table rendered with gt or flextable.

Usage

stratified_uni_reg(
  data,
  outcome,
  exposures,
  stratifier,
  approach = "logit",
  format = c("flextable", "gt"),
  theme = c("minimal"),
  show_ref = TRUE
)

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.". If FALSE, hide reference rows; a message reminds users to use show_ref = TRUE when reference rows are needed.

Value

A list of class c("gtregression", "stratified_uni_reg", ...) with elements:

table

A rendered gt_tbl or flextable.

table_display

Display-ready wide stratified results.

per_stratum

List of complete uni_reg() results by stratum.

models

List of fitted model objects by stratum.

model_summaries

List of model summaries by stratum.

variable_labels

Named character vector of display labels used for exposure variables.

reg_check

Regression diagnostics by stratum.

by

The stratifier variable.

levels

Strata included in the analysis.

approach

The regression approach used.

format

The output format used.

source

Function 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

$table

Rendered stratified regression table.

$table_display

Wide display data used to build the table.

$per_stratum

Full uni_reg() result objects by stratum.

$models

List of fitted model objects for each stratum.

$model_summaries

List of model summaries.

$reg_check

Diagnostic check results (when applicable).

See also

[multi_reg()], [plot_reg()], [identify_confounder()]

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
Characteristic
race = White
race = Black
race = Other
N OR (95% CI) p-value N OR (95% CI) p-value N OR (95% CI) p-value
age 96 0.95 (0.86–1.04) 0.226 26 1.05 (0.90–1.23) 0.526 67 0.94 (0.84–1.05) 0.297
lwt 96 0.98 (0.97–1.00) 0.123 26 0.99 (0.97–1.01) 0.517 67 0.97 (0.95–1.00) 0.056
smoke 96 26 67
No Ref. Ref. Ref.
Yes 5.76 (1.78–18.60) 0.003 3.30 (0.63–17.16) 0.156 1.25 (0.35–4.46) 0.731
Abbreviations: OR = Odds Ratio; CI = Confidence Interval.
Ref. = reference category.