Learn R Programming

mixgb (version 1.5.3)

impute_new: Impute new data with a saved mixgb imputer object

Description

Impute new data with a saved mixgb imputer object

Usage

impute_new(
  object,
  newdata,
  initial.newdata = FALSE,
  pmm.k = NULL,
  m = NULL,
  verbose = FALSE
)

Value

A list of m imputed datasets for new data.

Arguments

object

A saved imputer object created by mixgb(..., save.models = TRUE)

newdata

A data.frame or data.table. New data with missing values.

initial.newdata

Whether to use the information from the new data to initially impute the missing values of the new data. By default, this is set to FALSE, the original data passed to mixgb() will be used for initial imputation.

pmm.k

The number of donors for predictive mean matching. If NULL (the default), the pmm.k value in the saved imputer object will be used.

m

The number of imputed datasets. If NULL (the default), the m value in the saved imputer object will be used.

verbose

Verbose setting for mixgb. If TRUE, will print out the progress of imputation. Default: FALSE.

Examples

Run this code
set.seed(2022)
n <- nrow(nhanes3)
idx <- sample(1:n, size = round(0.7 * n), replace = FALSE)
train.data <- nhanes3[idx, ]
test.data <- nhanes3[-idx, ]

params <- list(max_depth = 3, subsample = 0.7, nthread = 2)
mixgb.obj <- mixgb(data = train.data, m = 2, xgb.params = params, nrounds = 10,
                   save.models = TRUE, save.models.folder = tempdir())

# obtain m imputed datasets for train.data
train.imputed <- mixgb.obj$imputed.data
train.imputed

# use the saved imputer to impute new data
test.imputed <- impute_new(object = mixgb.obj, newdata = test.data)
test.imputed

Run the code above in your browser using DataLab