I used the CHAID package from this link ..It gives me a chaid object which can be plotted..I want a decision table with each decision rule in a column instead of a decision tree. .But i dont understand how to access nodes and paths in this chaid object..Kindly help me.. I followed the procedure given in this link
i cant post my data here since it is too long.So i am posting a code which takes the sample dataset provided with chaid to perform the task.
copied from help manual of chaid:
library("CHAID")
### fit tree to subsample
set.seed(290875)
USvoteS <- USvote[sample(1:nrow(USvote), 1000),]
ctrl <- chaid_control(minsplit = 200, minprob = 0.1)
chaidUS <- chaid(vote3 ~ ., data = USvoteS, control = ctrl)
print(chaidUS)
plot(chaidUS)
Output:
Model formula:
vote3 ~ gender + ager + empstat + educr + marstat
Fitted party:
[1] root
| [2] marstat in married
| | [3] educr <HS, HS, >HS: Gore (n = 311, err = 49.5%)
| | [4] educr in College, Post Coll: Bush (n = 249, err = 35.3%)
| [5] marstat in widowed, divorced, never married
| | [6] gender in male: Gore (n = 159, err = 47.8%)
| | [7] gender in female
| | | [8] ager in 18-24, 25-34, 35-44, 45-54: Gore (n = 127, err = 22.0%)
| | | [9] ager in 55-64, 65+: Gore (n = 115, err = 40.9%)
Number of inner nodes: 4
Number of terminal nodes: 5
So my question is how to get this tree data in a decision table with each decision rule(branch/path) in a column..I dont understand how to access different tree paths from this chaid object..