model_donor: Model for donor-based imputation

View source: R/model_donor.R

model_donorR Documentation

Model for donor-based imputation

Description

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

Usage

model_donor(ds, M = is.na(ds), i = NULL, model_arg = NULL)

Arguments

ds

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

M

Missing data indicator matrix

i

Index for row of ds or NULL

model_arg

A list with two named elements (missing elements will be replaced by default values):

  • selection How to select the donors? Possible choices are: complete_rows (default), partly_complete_rows, knn_complete_rows, knn_partly_complete_rows

  • k number of selected closest donor (default: 10), only used for knn selections

Value

A "model" for predict_donor() which is merely a data frame.

See Also

predict_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 returns only complete rows
model_donor(ds_mis)
# with partly_complete and knn returned objects depends on i
model_donor(ds_mis,
  i = 2,
  model_arg = list(selection = "partly_complete_rows")
)
model_donor(ds_mis,
  i = 4,
  model_arg = list(selection = "partly_complete_rows")
)
model_donor(ds_mis,
  i = 5,
  model_arg = list(selection = "partly_complete_rows")
)
model_donor(ds_mis,
  i = 5,
  model_arg = list(selection = "knn_partly_complete_rows", k = 2)
)

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