[R] predict.rpart question

Damian Krstajic dkrstajic at hotmail.com
Tue Feb 26 15:37:10 CET 2008


Dear All,

I have a question regarding predict.rpart. I use
rpart to build classification and regression trees and I deal with data with
relatively large number of input variables (predictors). For example, I build an
rpart model like this

rpartModel <- rpart(Y ~ X, method="class",
minsplit =1, minbucket=nMinBucket,cp=nCp);

and get predictors used in building the model like
this

colnamesUsed<-unique(rownames(rpartModel$splits));

When later I apply the rpart model to predict the new
data I strip the input data from unneccessary columns and only use X columns
that exist in colnamesUsed. Unfortunately I get error message like this

Error: variable 'X' was fitted with type
"nmatrix.3522" but type "nmatrix.19" was supplied

The error message is correct. In the documentation it
clearly specifies that the predictors referred to in the right side of formula
(object) must be present by name in newdata, but I wonder why, if they are not
used?

Thanks

DK

_________________________________________________________________
Share what Santa brought you



More information about the R-help mailing list