Fit one model per exposure and return a clean regression table in flextable or gt format.
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 primitivesc("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'smodel_statselement and are not added to the publication table.- 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","uni_reg", ...) with elements:
- table
A
flextable(whenformat="flextable") orgt_tbl(whenformat="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; otherwiseNULL.- 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
}
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
Abbreviations: OR = Odds Ratio from Firth penalized logistic regression; CI = Confidence Interval.
Ref. = reference category.