[R] rpart.object help

Terry Therneau therneau at mayo.edu
Tue Dec 14 15:22:27 CET 2010


> On Sun, 12 Dec 2010, jagdeesh_mn wrote:
> 
>> Hi,
>>
>> Suppose i have generated an object using the following :
>> fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
>>
>> And when i print fit, i get the following :
>>
>> n= 81
>>
>> node), split, n, loss, yval, (yprob)
>>      * denotes terminal node
>>
>> 1) root 81 17 absent (0.7901235 0.2098765)
>>   2) Start>=8.5 62  6 absent (0.9032258 0.0967742)
>>     4) Start>=14.5 29  0 absent (1.0000000 0.0000000) *
>>     5) Start< 14.5 33  6 absent (0.8181818 0.1818182)
>>      10) Age< 55 12  0 absent (1.0000000 0.0000000) *
>>      11) Age>=55 21  6 absent (0.7142857 0.2857143)
>>        22) Age>=111 14  2 absent (0.8571429 0.1428571) *
>>        23) Age< 111 7  3 present (0.4285714 0.5714286) *
>>   3) Start< 8.5 19  8 present (0.4210526 0.5789474) *
>>
>> Is it possible to extract the splits alone as a matrix using
>> rpart.object?
>> If so, how?
> 
> 
>> Regards,
>> Jagdeesh

The best description of the rpart object is obtained with
help(rpart.object).  Each row of $frame describes one primary split.
More detailed descriptions of the (1 + ncompete + nprimary) split
variables for the node are found in the $splits and $csplits component.
You would need to look at summary.rpart to see how that is all indexed.
I would suggest grabbing a copy of the source code, since that contains
comments, which are stripped out when you print the R internal version.

Terry Therneau



More information about the R-help mailing list