getBranch: Get branch or list of branches from tree.

View source: R/user_funs.R

getBranchR Documentation

Get branch or list of branches from tree.

Description

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().

Usage

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")

anna-neufeld/treevalues documentation built on Sept. 21, 2023, 8:45 p.m.