node_table: Terminal-Node Table with Effective Sample Sizes

View source: R/node_table.R

node_tableR Documentation

Terminal-Node Table with Effective Sample Sizes

Description

Summarizes the nodes of a fitted ctree_stacked tree as a data frame, giving for each node the sequence of splits that defines it, its size in the stacked data, and its effective sample size on the original scale (stacked size divided by the number of imputations M).

Because a stacked dataset repeats every observation M times, node sizes printed by print() and plot() are M times larger than the number of observations they represent. Reporting those numbers directly overstates precision. This function performs the division so that node sizes can be reported and interpreted correctly.

Usage

node_table(object, terminal_only = TRUE, max_levels = NULL, digits = 3)

Arguments

object

An object of class "ctreeMI" as returned by ctree_stacked.

terminal_only

Logical. If TRUE (default) only terminal nodes are returned. If FALSE, inner nodes are included as well, which is useful for describing the tree structure.

max_levels

Integer or NULL. For splits on unordered factors with many levels, the number of levels to print before truncating (e.g. {A, B, +3 more}). NULL (default) prints the full level set.

digits

Integer. Number of decimal places for outcome summaries.

Details

Note that effective_n is exact at the root and is an observation-scale rescaling elsewhere. Because imputed values differ across imputations, an individual's M rows are not guaranteed to follow the same path down the tree, so effective_n should be read as the node's size expressed on the original scale rather than as a count of distinct individuals.

Value

A data frame of class "ctreeMI_nodes" with one row per node and the following columns:

node_id

Node identifier, matching print() and plot() output.

depth

Number of splits from the root to this node.

n_stacked

Number of rows in the stacked data.

effective_n

n_stacked / M: the node size on the scale of the original data. This is the number to report.

outcome summaries

Node means for numeric responses, or the proportion in the second level for binary factor responses. One column per response variable, so multivariate outcomes are supported.

path

The split conditions leading to the node, joined by " & ", suitable for pasting into a manuscript table.

conditions

A list-column holding the same conditions as a character vector, for programmatic use.

References

Sherlock, P., Mansolf, M., Hofheimer, J., Hockett, C. W., O'Connor, T. G., Roubinov, D., Graff, J. C., Lai, J.-S., Bush, N. R., Wright, R. J., & Chiu, Y.-H. M. (2026). Beyond linear risk: A machine learning approach to understanding perinatal depression in context. Multivariate Behavioral Research, 1–16. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/00273171.2026.2661244")}

See Also

ctree_stacked, report_ctreeMI

Examples

set.seed(1)
make_df <- function(i) {
  set.seed(i)
  n  <- 200
  x1 <- rnorm(n)
  x2 <- factor(sample(c("A", "B", "C"), n, TRUE))
  y  <- 2 * (x1 > 0) + 1.5 * (x2 == "A") + rnorm(n)
  data.frame(y = y, x1 = x1, x2 = x2)
}
imp_list <- lapply(1:10, make_df)
fit <- ctree_stacked(y ~ x1 + x2, data = imp_list, verbose = FALSE)

# Terminal nodes with effective sample sizes
node_table(fit)

# Truncate long factor level sets
node_table(fit, max_levels = 2)

# Include inner nodes
node_table(fit, terminal_only = FALSE)

ctreeMI documentation built on July 26, 2026, 1:06 a.m.