feat(chaid): emit split test stats (chi-square/p-value/df) in tree_nodes#1544
Merged
Conversation
Add p_value, adjusted_p_value, split_statistic, split_df columns to the CHAID tree_nodes tidy output (build_chaid_tree_nodes) so the interactive decision-tree renderer can show each split's adjusted p-value, chi-square statistic, and df, SPSS-style. Stats are stored on the splitting node (from the winning predictor's chi-square test) and left NA on leaves. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kei51e
approved these changes
Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the per-split test statistics to the CHAID
tree_nodestidy output so theinteractive decision-tree renderer (TAM) can display each split's adjusted
p-value, chi-square statistic, and df on the splitting node, SPSS-style.
What changed
R/chaid.R— when a node splits, store the winning predictor'schi-square statisticanddfon the node record (alongside the existingp_value/adjusted_p_value). Root and terminal records initialise the twonew fields to
NA.R/build_chaid.R—build_chaid_tree_nodes()emits four new columns:p_value,adjusted_p_value,split_statistic,split_df. Values arepopulated on splitting nodes and
NAon leaves (and on nodes whose bestcandidate failed the
alpha_splitgate). The rpart-compatible column order ispreserved; the new columns are appended, so the existing N-ary renderer keeps
working unchanged and simply ignores them until TAM reads them.
tests/testthat/test_build_chaid.R— new test asserting the stat columnsexist, splitting nodes carry finite chi-square / df / adjusted p-value in
[0,1], and leaves areNA.Verification
test_build_chaid.R: 45 passing / 0 failing. Manual check on a target thatdepends on a predictor produced
chi-square = 139.31, df = 1, adjusted p < 0.001on the root split,NAon leaves.Note
Front-end display degrades gracefully: until a bundled
exploratoryreleaseships these columns, TAM sees no split-stat columns and simply omits the block
(no crash).
🤖 Generated with Claude Code