After fitting and pruning an rpart model, it is often the case that one or
more of the original predictors is not used by any of the splits of the
final tree. It seems logical, therefore, that values for these "unused"
predictors would not be needed for prediction. But when predict() is called
on such models, all predictors seem to be required. Why is that, and can it
be easily circumvented?
Consider this example:
model <- rpart(Mileage ~ Weight + Disp. + HP, car.test.frame)
model
Error in eval(expr, envir, enclos) : object 'HP' not found
In this model, Disp. and Weight were used in splits, but HP was not. Thus I
expected to be able to perform predictions by providing values for just
Disp. and Weight, but predict() failed when I tried that, complaining that
HP was not also provided.
Thanks for any help you can provide. My apologies if I simply do not
understand how this works.
Best regards,
Jason