getObservations {bartMan} | R Documentation |
Get Observations Falling into Each Node
Description
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.
Usage
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'. |
Value
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 Column
tree_data_example <- transform(tree_data_example,
terminal = ifelse(is.na(var),
TRUE,
FALSE))
# Create Split Value Column
tree_data_example <- transform(tree_data_example,
splitValue = ifelse(terminal == FALSE,
value,
NA_integer_))
# get the observations
getObservations(data = input_data, treeData = tree_data_example)
[Package bartMan version 0.1.1 Index]