5

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

asked Dec 30, 2011 at 2:48
1
  • Are you talking about ctree found in the 'party' package? Commented Dec 30, 2011 at 3:57

3 Answers 3

12

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)

enter image description here

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 
answered Dec 30, 2011 at 4:09
1
  • @user1122211 - To show that DWin answered your question -- quite nicely I'd say -- and as another form of thanks to him, you can 'accept' it by clicking the checkmark directly to its left. Thanks. Commented Dec 31, 2011 at 5:50
1

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.

answered Nov 26, 2014 at 16:20
0

Let's say your ctree model is named ct. Then

print(ct)

worked for me to see the tree structure.

Dharman
33.9k27 gold badges103 silver badges153 bronze badges
answered Jun 12, 2021 at 19:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.