node_depth {bartMan}R Documentation

Calculate Node Depths in a Tree Data Frame

Description

Computes the depth of each node in a given tree data frame, assuming a binary tree structure. Requires the tree data frame to contain a logical column 'terminal' indicating terminal nodes.

Usage

node_depth(tree)

Arguments

tree

A data frame representing a tree, must contain a 'terminal' column.

Value

A vector of depths corresponding to each node in the tree.

Examples

data("tree_data_example")
# Create Terminal Column
tree_data_example <- transform(tree_data_example, terminal = ifelse(is.na(var), TRUE, FALSE))
# Get depths
depthList <- lapply(split(tree_data_example, ~treeNum + iteration),
                    function(x) cbind(x, depth = node_depth(x)-1))
# Turn into data frame
tree_data_example <- dplyr::bind_rows(depthList, .id = "list_id")


[Package bartMan version 0.1.0 Index]