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

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 
Sign up to request clarification or add additional context in comments.

1 Comment

@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.
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.

Comments

0

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

print(ct)

worked for me to see the tree structure.

Comments

Your Answer

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.