[R] predict.rpart question

2008-02-26 Thread Damian Krstajic

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] predict.rpart question

2008-02-26 Thread Damian Krstajic

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
_
Who's friends with who and co-starred in what?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.