Impute missing values based on a random forest model using xgboost::xgboost()
xgboostImpute(
formula,
data,
imp_var = TRUE,
imp_suffix = "imp",
verbose = FALSE,
nrounds = 100,
objective = NULL,
...,
edit_rules = NULL,
edit_control = NULL
)model formula for the imputation
A data.frame containing the data
TRUE/FALSE if a TRUE/FALSE variables for each imputed
variable should be created show the imputation status
suffix used for TF imputation variables
Show the number of observations used for training
and evaluating the RF-Model. This parameter is also passed down to
xgboost::xgboost() to show computation status.
max number of boosting iterations,
argument passed to xgboost::xgboost()
objective for xgboost,
argument passed to xgboost::xgboost()
Arguments passed to xgboost::xgboost()
Optional model-agnostic validator, applied jointly to the
assembled imputed LHS columns after all target fits; see vimpute().
Control object or named list; see vimpute_edit_control().
the imputed data set.
Other imputation methods:
hotdeck(),
impPCA(),
imputeCellEM(),
imputeCellIRMI(),
imputeCellM(),
imputeCellMCD(),
imputeCellwise(),
imputeRobust(),
imputeRobustChain(),
irmi(),
kNN(),
matchImpute(),
medianSamp(),
rangerImpute(),
regressionImp(),
sampleCat(),
vimmi,
vimpute()
data(sleep)
sleepx <- sleep
sleepx$Pred <- as.factor(LETTERS[sleepx$Pred])
sleepx$Pred[1] <- NA
# a numeric and a factor target imputed at once; nrounds = 30 keeps the
# example fast (the default is 100 boosting rounds)
# xgboostImpute() runs on vimpute(), which VIM backs with the suggested
# mlr3 stack -- skip the example where that stack is not installed.
if (requireNamespace("mlr3", quietly = TRUE) &&
requireNamespace("mlr3learners", quietly = TRUE) &&
requireNamespace("mlr3pipelines", quietly = TRUE)) {
imp <- xgboostImpute(Dream + Pred ~ BodyWgt + BrainWgt, data = sleepx, nrounds = 30)
head(imp)
}
#> BodyWgt BrainWgt NonD Dream Sleep Span Gest Pred Exp Danger Dream_imp
#> 1 6654.000 5712.0 NA 1.6 3.3 38.6 645 E 5 3 TRUE
#> 2 1.000 6.6 6.3 2.0 8.3 4.5 42 C 1 3 FALSE
#> 3 3.385 44.5 NA 2.2 12.5 14.0 60 A 1 1 TRUE
#> 4 0.920 5.7 NA 1.6 16.5 NA 25 E 2 3 TRUE
#> 5 2547.000 4603.0 2.1 1.8 3.9 69.0 624 C 5 4 FALSE
#> 6 10.550 179.5 9.1 0.7 9.8 27.0 180 D 4 4 FALSE
#> Pred_imp
#> 1 TRUE
#> 2 FALSE
#> 3 FALSE
#> 4 FALSE
#> 5 FALSE
#> 6 FALSE