predict_donor: Prediction for donor-based imputation

View source: R/model_donor.R

predict_donorR Documentation

Prediction for donor-based imputation

Description

This function is intended to be used inside of impute_unsupervised() as predict_fun.

Usage

predict_donor(
  ds_donors,
  ds,
  M = is.na(ds),
  i,
  donor_aggregation = "choose_random"
)

Arguments

ds_donors

Data set with donors, normally generated by model_donor()

ds

The data set to be imputed. Must be a data frame with column names.

M

Missing data indicator matrix

i

Index of row of ds which should be imputed

donor_aggregation

Type of donor aggregation. Can be one of 'choose_random' and 'average'.

Value

The imputation values for row i.

See Also

model_donor()

Examples

set.seed(123)
ds_mis <- data.frame(X = rnorm(10), Y = rnorm(10))
ds_mis[2:4, 1] <- NA
ds_mis[4:6, 2] <- NA
# default for ds_donors and predict_donors
ds_donors <- model_donor(ds_mis)
predict_donor(ds_donors, ds_mis, i = 2)
predict_donor(ds_donors, ds_mis, i = 4)
# with partly_complete, knn and average of neighbors
ds_donors <- model_donor(
  ds_mis,
  i = 5, model_arg = list(selection = "knn_partly_complete_rows", k = 2)
)
ds_donors
predict_donor(ds_donors, ds_mis, i = 5, donor_aggregation = "average")

imputeGeneric documentation built on March 18, 2022, 6:35 p.m.