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 -- View this message in context: http://r.789695.n4.nabble.com/rpart-object-help-tp3085054p3085054.html Sent from the R help mailing list archive at Nabble.com.
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?What do you think 'rpart.object' is? There is no such function in R. If you read help("rpart.object") it describes the returned object. You are probably looking for fit$frame, but if you want something else, study rpart:::print.rpart to see how that output is computed.> Regards, > Jagdeesh-- 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
> 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, >> JagdeeshThe 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