[R] rpart$where and predict.rpart
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Jul 22 12:51:42 CEST 2008
On Tue, 22 Jul 2008, Chua Siang Li wrote:
>
> Hello there. I have fitted a rpart model.
> > rpartModel <- rpart(y~., data=data.frame(y=y,x=x),method="class", ....)
> and can use rpart$where to find out the terminal nodes that each
> observations belongs.
> Now, I have a set of new data and used predict.rpart which seems to give
> only the predicted value with no information similar to rpart$where.
> May I know how to find out the terminal nodes that each new observations
> belongs to?
You need to read the code to answer questions about internals. A very
quick glance at predict.rpart would have told you that
where <- pred.rpart(object, rpart.matrix(newdata))
is what you are looking for. (Note that pred.rpart like many other
internal functions is not exported from the name space.)
> Many thanks.
> ----
> Chua Siang Li
> Consultant - Operations Research
> Acceval Pte Ltd
> Tel: 6297 8740
> Email: siang.li.chua at acceval-intl.com
> Website: www.acceval-intl.com
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list