| vimpute | R Documentation |
Impute missing values with prefered model, sequentially, with hyperparametertuning and with PMM (if wanted)
vimpute(
data,
...,
considered_variables = names(data),
method = setNames(as.list(rep("ranger", length(considered_variables))),
considered_variables),
pmm = FALSE,
pmm_k = NULL,
pmm_k_method = "mean",
learner_params = NULL,
formula = FALSE,
makeNA = NULL,
donorcond = NULL,
sequential = TRUE,
nseq = 10,
eps = 0.005,
imp_var = TRUE,
keep_all_columns = TRUE,
pred_history = FALSE,
tune = FALSE,
verbose = FALSE,
boot = NULL,
robustboot = "stratified",
uncert = "pmm",
m = 1L,
seed = NULL,
tuned_params = NULL,
tune_control = NULL,
predictors = NULL,
visit_sequence = "asis",
spec = NULL
)
data |
Dataset with missing values. Provide as a data.table. |
... |
Optional bare grammar formulas, one per variable:
|
considered_variables |
A character vector of variable names to be either imputed or used as predictors, excluding irrelevant columns from the imputation process. Excluded columns are still returned unchanged by default (see |
method |
Specifies the imputation method for each variable. Can be provided either:
|
pmm |
Predictive Mean Matching (PMM) settings. Can be provided:
|
pmm_k |
Number of nearest neighbors used in PMM. Accepted forms:
|
pmm_k_method |
Aggregation method used when
|
learner_params |
Hyperparameters for the chosen methods. Can be provided in three ways:
|
formula |
Optional modeling formula to restrict or transform predictor variables. Only supported for methods whose registry entry declares formula support: among the built-ins regularized (glmnet), robust (lmrob/glmrob), gam (mgcv::gam), robgam (robust GAM), and restricted (ECOSolveR least-squares with validate rules) Provide as a named list, e.g.:
|
makeNA |
Optional named list that defines additional values to be treated as imputable missing
values per variable, similar to |
donorcond |
Optional named list of donor conditions per variable, similar to |
sequential |
If TRUE, all variables with missing data are imputed sequentially across iterations. |
nseq |
Maximum number of iterations (if sequential is TRUE). |
eps |
Convergence threshold on the per-variable relative change between
iterations: for numeric variables the mean squared change of the imputed
values divided by the variance of the observed values, for factors the
share of imputed cells whose category changed. The sequential process
stops early once the largest per-variable change stays below |
imp_var |
If TRUE, additional columns indicating imputed values (VAR_imp) are added. |
keep_all_columns |
If TRUE (default), the full input is returned: columns excluded via
|
pred_history |
If TRUE, all predicted values across all iterations are stored. |
tune |
Hyperparameter tuning flag. Can be:
|
verbose |
If TRUE additional debugging output is provided |
boot |
If TRUE, bootstrap resampling is applied before model fitting to account
for model uncertainty. Defaults to |
robustboot |
Bootstrap strategy when |
uncert |
Imputation uncertainty method applied to numeric predictions:
|
m |
Number of multiple imputations. Default: 1 (single imputation).
When |
seed |
Optional single number for reproducibility. Applied once via
|
tuned_params |
Optional named list mapping variable names to learner parameter lists
(e.g. |
tune_control |
|
predictors |
Optional per-variable predictor control, the equivalent of mice's
|
visit_sequence |
Order in which the variables with missings are imputed:
|
spec |
|
Missingness assumptions. Like all conditional (fully
conditional specification) imputation, vimpute() assumes the data
are MAR (missing at random: the probability of missingness may
depend on observed values) – which includes MCAR
(missing completely at random) as a special case. Under MNAR
(missingness depending on the unobserved values themselves) imputations
and downstream estimates can be biased, and no imputation method can fix
this from the observed data alone; sensitivity analyses are advisable.
makeMissing generates MCAR/MAR/MNAR missingness in complete
data for exactly such simulation-based checks, and
overimpute diagnoses the calibration of the imputation
model on the observed cells.
For m = 1: the imputed dataset, classed like the input
(data.frame in, data.frame out; data.table in, data.table out). When
tune = TRUE the tuning report is attached as
attr(result, "tuning_log"); when pred_history = TRUE the
prediction history is attached as attr(result, "pred_history");
sequential runs attach the per-variable convergence matrix as
attr(result, "convergence") and the chain statistics as
attr(result, "chain"); the per-variable model quality (NRMSE/PFC,
out-of-bag for ranger, in-sample otherwise) is attached as
attr(result, "model_error") – the return is always the data
itself, never a wrapper list.
For m > 1: a vimmi object.
Eileen Vattheuer, Matthias Templ, Alexander Kowarik
Other imputation methods:
hotdeck(),
impPCA(),
imputeCellEM(),
imputeCellIRMI(),
imputeCellM(),
imputeCellMCD(),
imputeCellwise(),
imputeRobust(),
imputeRobustChain(),
irmi(),
kNN(),
matchImpute(),
medianSamp(),
rangerImpute(),
regressionImp(),
sampleCat(),
vimmi,
xgboostImpute()
## Not run:
# Single imputation (default)
x <- vimpute(data = sleep, sequential = FALSE)
# Sequential imputation with 3 iterations
y <- vimpute(data = sleep, sequential = TRUE, nseq = 3)
# Impute only selected variables
z <- vimpute(data = sleep, considered_variables =
c("Sleep", "Dream", "Span", "BodyWgt"), sequential = FALSE)
# Multiple imputation (m = 5) with bootstrap and residual uncertainty
# Returns a vimmi object
result <- vimpute(data = sleep, method = "ranger", sequential = FALSE,
imp_var = FALSE, m = 5, boot = TRUE, uncert = "resid")
print(result)
# Extract completed datasets
d1 <- vim_complete(result, 1) # first imputed dataset
all_d <- vim_complete(result, "all") # list of 5 datasets
long_d <- vim_complete(result, "long") # long format with .imp column
# Fit a model on each imputed dataset
fits <- with(result, lm(Sleep ~ Dream + Span))
# Multiple imputation with robust method and residual uncertainty
result2 <- vimpute(data = sleep, method = "robust", m = 5,
boot = TRUE, robustboot = "stratified",
uncert = "normalerror")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.