rrp.predict {rrp} | R Documentation |
This method is a simple nearest neighbor based on the RRP dissimilarity matrix. It can be used also as a supervised method, i.e. using the outcome variable in the construction of the RRP dissimilarity matrix and by imputing missing values to the test set.
rrp.predict(x, y, train, test, k = 1)
x |
a dist object with attribute method = RRP |
y |
numeric vector of train outcomes |
train |
the vecotr of indexes of the training set |
test |
the vector of training indexes of test set |
k |
number of nearest to consider |
a vector of type numeric
with predicted outcomes.
S.M. Iacus
Iacus, S.M., Porro, G. (2006) Random Recursive Partitioning and its applications to missing data imputation, classification and average treatment effect estimation, submitted.
require(MASS) attach(birthwt) race <- factor(race, labels= c("white", "black", "other")) ptd <- factor(ptl>0) ftv <- factor(ftv) levels(ftv)[-(1:2)] <- "2+" table(ftv) bwt <- data.frame(bwt, age, lwt, race, smoke=(smoke>0), ptd, ht=(ht>0), ui = (ui>0), ftv) detach() rm(race, ptd, ftv) set.seed(123) n <- dim(bwt)[1] test <- sample(1:n, 15) train <- (1:n)[-test] D <- rrp.dist(bwt[,-1]) true.wht <- bwt$bwt[test] pred.wht <- rrp.predict(D, bwt$bwt[train], train, test) mean(pred.wht-true.wht) sd(pred.wht-true.wht) mod <- lm(bwt ~ ., data=bwt[train,]) pred.wht <- predict(mod, newdata = bwt[test,]) mean(pred.wht-true.wht) sd(pred.wht-true.wht)