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. For binary-outcome approaches (
"logit","firth","logbinomial","robpoisson") the outcome may be numeric 0/1 or 1/2 (2 is the event; integer or double), logical (TRUEis the event), or a two-level factor or character variable (the second level is the event, which is reported in a message). The same factor, character and logical coding is accepted by"poisson".- 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. Printing this element renders a publication-ready table; individual diagnostic rows remain available for programmatic use. Other approaches return a message.
- 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.
Confidence intervals are Wald intervals; for approach = "linear"
they use the t distribution with the residual degrees of freedom (as
confint() for lm), consistent with the t-based p-values.
Factor exposures are always fitted with treatment contrasts (each level
versus the reference), whatever options(contrasts = ) or a
contrasts attribute says. An exposure whose model cannot be fitted
is kept in the table with a dash and named in a footnote and in
failed_exposures.
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.