Skip to contents

Fit one model per exposure and return a clean regression table in flextable or gt format.

Usage

uni_reg(
  data,
  outcome,
  exposures,
  approach = "logit",
  format = c("flextable", "gt"),
  theme = c("minimal"),
  model_stats = FALSE,
  show_ref = TRUE
)

Arguments

data

A data frame containing the outcome and exposure variables.

outcome

Character scalar; outcome column name. Quoted and bare names are accepted.

exposures

Character vector; exposure column names. Quoted names are recommended in scripts, and bare names are also accepted.

approach

Regression approach. One of "logit", "firth", "logbinomial", "poisson", "robpoisson", "linear", or "negbin". Use "firth" for Firth penalized logistic regression, especially with sparse cells or separation.

format

One of "flextable" (default) or "gt".

theme

Preset name (e.g. "minimal", "striped", "clinical", "shaded", "jama") or primitives c("plain","zebra","lines","labels_bold","compact","header_shaded")

model_stats

Logical; if TRUE, extract model-fit statistics such as AIC, BIC, log-likelihood, deviance, pseudo R-squared for non-linear models, and R-squared for linear models. Statistics are stored in the returned object's model_stats element and are not added to the publication table.

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","uni_reg", ...) with elements:

table

A flextable (when format="flextable") or gt_tbl (when format="gt").

table_body

Data frame of numeric estimates and CIs.

table_display

Data frame for display (headers + levels).

models

List of fitted univariate models.

model_summaries

Per-model summary() results.

model_stats

Model-fit statistics when model_stats = TRUE; otherwise NULL.

variable_labels

Named character vector of display labels used for exposure variables.

reg_check

Diagnostics for linear models; message otherwise.

approach, format, source

Metadata fields.

Details

Use this when you want a quick crude association table before building an adjusted model. The fitted models are kept in the returned object, so the formatted table does not hide the underlying analysis.

If exposure variables have a "label" attribute, for example from labelled::var_label(), those labels are used automatically in the displayed table and plots. Internal matching still uses the original column names.

Examples

d <- mtcars
if (requireNamespace("gt", quietly = TRUE)) {
  uni_reg(d, "am", c("mpg","cyl"), approach = "logit", format = "gt")$table
}
Characteristic N OR (95% CI) p-value
mpg 32 1.36 (1.09-1.70) 0.008
cyl 32 0.50 (0.30-0.82) 0.006
Abbreviations: OR = Odds Ratio; CI = Confidence Interval.
if (requireNamespace("flextable", quietly = TRUE)) { ft <- uni_reg(d, "am", c("mpg","cyl"), approach = "logit", format = "flextable") class(ft$table) } #> [1] "flextable" endometrial_data <- data_endometrial endometrial_data$HG <- factor(endometrial_data$HG, levels = c(0, 1)) endometrial_data$NV <- factor(endometrial_data$NV, levels = c(0, 1)) uni_reg(endometrial_data, HG, c(NV, PI, EH), approach = firth, format = gt)$table
Characteristic N OR (95% CI) p-value
NV 79
0
Ref.
1
76.37 (9.27-9,962.22) <0.001
PI 79 1.01 (0.97-1.06) 0.576
EH 79 0.03 (0.01-0.13) <0.001
Abbreviations: OR = Odds Ratio from Firth penalized logistic regression; CI = Confidence Interval.
Ref. = reference category.