Re: [R] rpart$where and predict.rpart

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 22 Jul 2008 11:51:42 +0100 (BST)

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

______________________________________________
R-help_at_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.
Received on Tue 22 Jul 2008 - 10:58:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jul 2008 - 13:32:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive