
Analysis-aware multiple imputation for narrow regression models
Source:R/multi_impute_analysis.R
multi_impute_analysis.RdGenerate multiple imputations conditional on a specified downstream regression model. Validity requires MAR, a correctly specified conditional imputation model, and adequate SMCFCS or jomo convergence. This experimental interface is deliberately narrow: exactly one continuous covariate may contain missing values, while the outcome, all other predictors, auxiliary variables, and any grouping variable must be fully observed.
Arguments
- data
A data frame containing the analysis variables.
- formula
A two-sided additive model formula. For
model = "lmer", exactly one random-intercept term of the form(1 | group)is required.- missing
A single character string naming the continuous numeric covariate to impute. It must occur as a main-effect predictor in
formulaand must be the only column indatacontaining missing values.- model
One of
"lm","glm", or"lmer". The"glm"route is restricted to binomial-logit regression. The"lmer"route is restricted to a Gaussian random-intercept model.- m
Integer number of completed datasets. Must be at least two.
- auxiliary
Character vector naming fully observed numeric columns used only by the imputation model. They cannot duplicate formula variables. Derived terms must be created explicitly in
databefore calling this function.- seed
Integer random seed.
- control
Named list of engine controls. The
"lm"route accepts no controls. The"glm"route acceptsnumit(default 20) andrjlimit(default 100000). The"lmer"route acceptsnburn(default 1000) andnbetween(default 100).
Value
An object with classes "pigauto_analysis_mi" and "pigauto_mi".
Its datasets component is a list of m completed data frames compatible
with with_imputations() and pool_mi(). The object also records the
analysis model, formula, engine, controls, engine version, seed, runtime
provenance, and imputed-variable metadata. Any engine warning aborts the
call instead of returning an inference-ready object.
Experimental scope
This function does not fit pigauto's phylogenetic baseline or graph neural
network and does not propagate posterior-tree uncertainty. The "lm" route
uses proper Bayesian Normal-regression draws. The "glm" route requires the
optional smcfcs package, and the "lmer" route requires the optional
jomo and lme4 packages. Interactions, transformed terms, random slopes,
nested or crossed random effects, multiple incomplete variables, missing
outcomes, and pooling of variance components or BLUPs are unsupported.
Examples
set.seed(11)
dat <- data.frame(
y = stats::rnorm(80),
x = stats::rnorm(80),
z = stats::rnorm(80)
)
dat$x[seq(4, 80, by = 5)] <- NA_real_
mi <- multi_impute_analysis(
dat, y ~ x + z, missing = "x", model = "lm", m = 5, seed = 12
)
fits <- with_imputations(
mi, function(d) stats::lm(y ~ x + z, data = d), .progress = FALSE
)
pool_mi(fits)
#> Pooled estimates from 5 multiply-imputed fits (Rubin's rules)
#> Confidence level: 95%
#>
#> term estimate std.error df statistic p.value conf.low conf.high
#> (Intercept) -0.1106 0.1001 5024. -1.105 0.2691 -0.3067 0.08558
#> x -0.1751 0.1131 63.40 -1.548 0.1266 -0.4011 0.05092
#> z -0.1428 0.1128 1935. -1.266 0.2057 -0.3641 0.07846
#> fmi riv
#> 0.02860 0.02904
#> 0.2737 0.3354
#> 0.04645 0.04763