This function takes a dataframe of trees, which is output from a BART model, and organizes it into a list of tree structures. It allows for filtering based on iteration number, tree number, and optionally reordering based on the maximum depth of nodes or variables.

treeList(trees, iter = NULL, treeNo = NULL)

Arguments

trees

A dataframe that contains the tree structures generated by a BART model. Expected columns include iteration, treeNum, parent, node, obsNode,

iter

An integer specifying the iteration number of trees to be included in the output. If NULL, trees from all iterations are included.

treeNo

An integer specifying the number of the tree to include in the output. If NULL, all trees are included.

Value

A list of tidygraph objects, each representing the structure of a tree. Each tidygraph object includes node and edge information necessary for visualisation.

Examples

if (FALSE) {
df_trees <- extractTreeData(model = my_model, data = my_data)
trees_list <- treeList(df_trees)
}