Generates custom labels for each node in an rpart classification tree to aid
in understanding CART's pruning algorithm
Usage
annotree(
mod,
show_classes = TRUE,
show_gt = FALSE,
show_cp = FALSE,
show_pruned = FALSE,
show_min = FALSE,
show_leaf_dev = FALSE,
show_internal_dev = FALSE,
main = NULL
)Arguments
- mod
an
rpartobject- show_classes
logical. If
TRUEshow class labels and counts. Defaults toTRUE.- show_gt
logical. If
TRUEthe g(t) term (misclassification reduction per split) is included. Defaults toFALSE.- show_cp
logical. If
TRUEthe complexity parameter (cp) value, calculated as g(t) divided by root node deviance is included. Defaults toFALSE.- show_pruned
logical. If
TRUEthe nodes slated for pruning are plotted in a distinct color. Defaults toFALSE.- show_min
logical. If
TRUEthe node with minimum g(t) is labeled "*minimum". Defaults toFALSE.- show_leaf_dev
logical. If
TRUEleaves are labeled with "dev" (misclassified cases). Defaults toFALSE.- show_internal_dev
logical. If
TRUEinternal nodes are labeled with "dev" (misclassified cases). Defaults toFALSE.- main
An optional title for the plot.
Details
This function is primarily used to create informative labels for internal nodes and leaves in classification trees.
For leaf nodes, it displays the word
"leaf"and the node's deviance.For internal nodes, it can display the g(t) equation, cp value, and optionally indicate the node with the smallest g(t).
