[R] rpart - predict terminal nodes for new observations

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed May 16 17:41:09 CEST 2012



On 15.05.2012 16:30, tudor wrote:
> Dear useRs:
>
> Is there a way I could predict the terminal node associated with a new data
> entry in an rpart environment? In the example below, if I had a new data
> entry with an AM of 5, I would like to link it to the terminal node 2. My
> searches led to http://tolstoy.newcastle.edu.au/R/e4/help/08/07/17702.html
> but I do not seem to be able to operationalize Professor Ripley's
> suggestions.


Use the predict() function.

Uwe Ligges


> Many thanks.
>
> Tudor
>
>> tree.prune
> n= 2400
>
> node), split, n, loss, yval, (yprob)
>        * denotes terminal node
>
> 1) root 2400 779 0 (0.6754167 0.3245833)
>    2) AM<  6.5 1428 254 0 (0.8221289 0.1778711) *
>    3) AM>=6.5 972 447 1 (0.4598765 0.5401235)
>      6) P>=10.39666 390  86 0 (0.7794872 0.2205128) *
>      7) P<  10.39666 582 143 1 (0.2457045 0.7542955) *
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/rpart-predict-terminal-nodes-for-new-observations-tp4630104.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



More information about the R-help mailing list