Perform Regression Analysis
regression_analysis.RdThis function performs regression analysis on multiply imputed data and pools
the results using Rubin's Rules. It supports fixed-effects, random-effects,
and mixed-effects models, each available in a linear variant (Gaussian /
identity link) or a non-linear variant (generalized models with a family,
e.g. logistic or Poisson).
Usage
regression_analysis(
births,
targets,
cat_label,
exposure_level_col,
regression_formula,
output_dir,
model_type = "mixed",
model_family = NULL
)Arguments
- births
A data frame containing the birth data with imputation identifiers.
- targets
A character vector of target variables (health outcomes).
- cat_label
A character vector of exposure categories (excluding reference).
- exposure_level_col
A character string for the exposure level column name.
- regression_formula
A formula object or character string for the regression model.
- output_dir
A character string for the output directory path.
- model_type
A character string selecting the effects structure. One of
"mixed"(default, fixed + random effects),"random"(random-intercept only), or"fixed"(no random effects).- model_family
The error distribution / link for non-linear (generalized) models. Accepts
NULL(default, a linear/Gaussian model), a family name such as"binomial"or"poisson", the special value"multinomial"(multi-level categorical outcome, fitted withnnet::multinom()for fixed effects ormclogit::mblogit()for random-/mixed-effects), astats::family()object, or a family-generating function. When non-NULL, generalized models are fitted.
Details
The fitting engine is selected from the combination of model_type and
model_family:
| model_type | linear (model_family = NULL) | non-linear (model_family set) |
"fixed" | stats::lm() | stats::glm() |
"random" | lme4::lmer() | lme4::glmer() |
"mixed" | lme4::lmer() | lme4::glmer() |
Multi-level categorical outcomes are supported via multinomial logistic
regression (model_family = "multinomial"): fixed-effects fits use
nnet::multinom(), while random- and mixed-effects fits use
mclogit::mblogit(). Multinomial results include a y.level column
identifying the outcome category (relative to the reference level) that each
pooled estimate refers to.