How to extract tree structure from ctree function?

I am trying to extract tree information from ctree output. I tried the information on the "BinaryTree" class, but without success. Any input is appreciated.

thanks

+6
source share
2 answers

The ctree objects are S4 objects, at least from the top, and the tree information is in the "tree" slot. "The slot tree can be accessed using the @ operator. If you take the first example on the help page (ctree), you can get a graphic display with:

plot(airct) 

enter image description here

And then you can look at the tree branches by going through list operations. The "leaves" of the tree are descendants of nodes with a "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 in nodes above the leaves can also be restored:

 > 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 be restored if you know the node number:

 > nodes(airct,4) [[1]] 4) Temp <= 77; criterion = 0.997, statistic = 11.599 5)* weights = 48 4) Temp > 77 6)* weights = 21 
+11
source

mlmeta R package converts installed ctree models to SAS code. It can be easily adapted to other languages ​​and, as a rule, is useful for internal objects of the object.

+1
source

Source: https://habr.com/ru/post/904719/


All Articles