Learn R Programming

missRanger (version 1.0.4)

pmm: Predictive Mean Matching

Description

This function is used internally only but might help others to implement an efficient way of doing predictive mean matching on top of any prediction based missing value imputation. It works as follows: For each predicted value of a vector xtest, the closest k predicted values of another vector xtrain are identified by k-nearest neighbour. Then, one of those neighbours is randomly picked and its corresponding observed value in ytrain is returned.

Usage

pmm(xtrain, xtest, ytrain, k = 1L, seed = NULL)

Arguments

xtrain

Vector with predicted values in the training data set.

xtest

Vector with predicted values in the test data set.

ytrain

Vector with observed response in the training data set.

k

Number of nearest neighbours to choose from. Set k = 0 if no predictive mean matching is to be done.

seed

Integer random seed.

Value

Vector with predicted values in the test data set based on predictive mean matching.

Examples

Run this code
# NOT RUN {
pmm(xtrain = c(0.2, 0.2, 0.8), xtest = 0.3, ytrain = c(0, 0, 1), k = 1) # 0
pmm(xtrain = c(0.2, 0.2, 0.8), xtest = 0.3, ytrain = c(0, 0, 1), k = 3) # 0 or 1
pmm(xtrain = c("A", "A", "B"), xtest = "B", ytrain = c("B", "A", "B"), k = 1) # B
pmm(xtrain = c("A", "A", "B"), xtest = "B", ytrain = c("B", "A", "B"), k = 2) # A or B
# }

Run the code above in your browser using DataLab