This function determines which observations from a given dataset fall into which nodes of a tree, based on a tree structure defined in treeData. The treeData object must include iteration, treeNum, var, and splitValue columns.
getObservations(data, treeData)
Arguments
data: A data frame used to build BART model.
treeData: A data frame representing the tree structure, including the necessary columns iteration, treeNum, var, and splitValue.
Returns
A modified version of treeData that includes two new columns: obsNode and noObs. obsNode lists the observations falling into each node, and noObs provides the count of observations for each node.
Examples
data("tree_data_example")# Create Terminal Columntree_data_example <- transform(tree_data_example, terminal = ifelse(is.na(var),TRUE,FALSE))# Create Split Value Columntree_data_example <- transform(tree_data_example, splitValue = ifelse(terminal ==FALSE, value,NA_integer_))# get the observationsgetObservations(data = input_data, treeData = tree_data_example)