I am trying to extract the tree information from the output of ctree. I tried the Class "BinaryTree" info but with no success. Any input is appreciated.
Thank You
The ctree objects are S4 objects at least at the top, and the tree information is in the "tree" slot. The "tree slot can be access ed with the @ operator. If you take the first example in the help(ctree) page you can get a graphical display with:
plot(airct)
And then you can look are branches of the tree by traversing with list operations. The "leaves" of the tree are descendents of nodes with "terminal"==TRUE:
> airct@tree$right$terminal
[1] FALSE
> airct@tree$left$terminal
[1] FALSE
> airct@tree$right$right$terminal
[1] TRUE
> airct@tree$right$left$terminal
[1] TRUE
> airct@tree$left$left$terminal
[1] TRUE
> airct@tree$left$right$terminal
[1] FALSE
Information at nodes above the leaves can also be recovered:
> airct@tree$left$right
4) Temp <= 77; criterion = 0.997, statistic = 11.599
5)* weights = 48
4) Temp > 77
6)* weights = 21
This is the same information that the nodes
function will recover if you know the number of the node:
> nodes(airct,4)
[[1]]
4) Temp <= 77; criterion = 0.997, statistic = 11.599
5)* weights = 48
4) Temp > 77
6)* weights = 21
The mlmeta R package converts fitted ctree models to SAS code. It can be easily adapted to other languages and is generally instructive on the internals of the object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With