Description Usage Arguments Value Examples
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.
1 |
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 |
seed |
Integer random seed. |
Vector with predicted values in the test data set based on predictive mean matching.
1 2 3 4 | 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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.