Can I store ctree splitting rules and terminal nodes plots in a table?

236 views Asked by At

I would like to create a table to summarise the splitting rules of a conditional inference tree (ctree) so that each predictor is in a separate column and each row is a terminal node with corresponding values from each of the predictors. For example:

IrisTree <- ctree(Species ~ ., data = iris)

which results in this tree:

ctree on iris data

and store the results in a way such as below:

summary table

Also, I would like to embed in a last column each of the plots resulting at terminal nodes, but I am struggling to find a way to store plots separately. Is it possible?

1

There are 1 answers

0
Achim Zeileis On

Split rules

The split summary can be built on the (still unexported) function .list.rules.party():

partykit:::.list.rules.party(IrisTree)
##                                                               2 
##                                           "Petal.Length <= 1.9" 
##                                                               5 
## "Petal.Length > 1.9 & Petal.Width <= 1.7 & Petal.Length <= 4.8" 
##                                                               6 
##  "Petal.Length > 1.9 & Petal.Width <= 1.7 & Petal.Length > 4.8" 
##                                                               7 
##                        "Petal.Length > 1.9 & Petal.Width > 1.7" 

For further processing of split summaries, see also the following answers:

Plotting subtrees

The individual plots can be easily obtained by subsetting the tree suitably. In general if tree is a party object, then tree[i] is the party object rooted in Node i. These can still be plotted as before.

Thus, when selecting and plotting only a terminal node, this gives you the panel from that terminal node:

plot(IrisTree[5])

terminal node 5 from iris tree