Given an rpart tree and a node number, returns a vector of strings that describes the branch which defines the node. If no node number is provided, returns a list describing every branch in the tree. Useful for extracting individual branches, which are necessary inputs to branchInference().

getBranch(tree, nn = NULL)

Arguments

tree

An rpart object.

nn

A node number that corresponds to a valid node in tree. The list of valid node numbers can be obtained with row.names(tree$frame) or by plotting tree with treeval.plot(). The node number can be passed in as either a character string or an integer. If no node number is provided, a list of all branches in the tree will be returned.

Value

Either a single branch (which is a vector of splits) or (if nn=NULL), a list of all branches in the tree.

Examples

bls.tree <- rpart::rpart(kcal24h0~hunger+disinhibition+resteating+rrvfood+liking+wanting, model = TRUE, data = blsdata, cp=0.02) branch <- getBranch(bls.tree, 8) branchInference (bls.tree, branch, type="sib")
#> #> Sample statistic: -435.6817 #> 95% confidence interval: -1106.747, 136.5523 #> Type: sib #> p-value for test that param=0: 0.9002555 #> Conditioning Set: #> Object of class Intervals_full #> 2 intervals over R: #> (-543.236399481531, -428.125574226105) #> (428.125574226104, 929.97322312961)