Returns a names list where each element contains the splits on the path from the root to the selected nodes.

path.rpart(tree, nodes, pretty = 0, print.it = TRUE)

Arguments

tree

fitted model object of class "rpart". This is assumed to be the result of some function that produces an object with the same named components as that returned by the rpart function.

nodes

an integer vector containing indices (node numbers) of all nodes for which paths are desired. If missing, user selects nodes as described below.

pretty

an integer denoting the extent to which factor levels in split labels will be abbreviated. A value of (0) signifies no abbreviation. A NULL, the default, signifies using elements of letters to represent the different factor levels.

print.it

Logical. Denotes whether paths will be printed out as nodes are interactively selected. Irrelevant if nodes argument is supplied.

Value

A named (by node) list, each element of which contains all the splits on the path from the root to the specified or selected nodes.

Graphical Interaction

A dendrogram of the rpart object is expected to be visible on the graphics device, and a graphics input device (e.g. a mouse) is required. Clicking (the selection button) on a node selects that node. This process may be repeated any number of times. Clicking the exit button will stop the selection process and return the list of paths.

Details

The function has a required argument as an rpart object and a list of nodes as optional arguments. Omitting a list of nodes will cause the function to wait for the user to select nodes from the dendrogram. It will return a list, with one component for each node specified or selected. The component contains the sequence of splits leading to that node. In the graphical interaction, the individual paths are printed out as nodes are selected.

References

This function was modified from path.tree in S.

See also

Examples

fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis) print(fit)
#> n= 81 #> #> node), split, n, loss, yval, (yprob) #> * denotes terminal node #> #> 1) root 81 17 absent (0.79012346 0.20987654) #> 2) Start>=8.5 62 6 absent (0.90322581 0.09677419) #> 4) Start>=14.5 29 0 absent (1.00000000 0.00000000) * #> 5) Start< 14.5 33 6 absent (0.81818182 0.18181818) #> 10) Age< 55 12 0 absent (1.00000000 0.00000000) * #> 11) Age>=55 21 6 absent (0.71428571 0.28571429) #> 22) Age>=111 14 2 absent (0.85714286 0.14285714) * #> 23) Age< 111 7 3 present (0.42857143 0.57142857) * #> 3) Start< 8.5 19 8 present (0.42105263 0.57894737) *
path.rpart(fit, node = c(11, 22))
#> #> node number: 11 #> root #> Start>=8.5 #> Start< 14.5 #> Age>=55 #> #> node number: 22 #> root #> Start>=8.5 #> Start< 14.5 #> Age>=55 #> Age>=111