0

I have a similar question as in

how to get all terminal nodes - weight & response prediction 'ctree' in r

I would like to get the result like this. Nevertheless, the nodes()-function does not work properly in my case. And I do not understand why.

tree <- ctree(DV ~ IV, data = data)

nodes(tree, unique(where(tree))) 

When I run it, I allways get the following error:

Error in match.arg(data, choices = c("all", "organization", "endpoint",  : 
  'arg' must be NULL or a character vector

What can I do in order to make the function work?

Thank you very much in advance!

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Could you please state what information you want to extract exactly? The `nodes()` and `where()` functions from `party` are not available in `partykit`. Instead a cleaner and more standard interface has been set up, e.g., you can easily subset trees with the `[` operator etc. Hence, if you say what you want to extract, we can easily provide guidance on how to do so in `partykit`. – Achim Zeileis Mar 02 '18 at 13:29

1 Answers1

0

Try using the ctree function of the party package:

library(party)
set.seed(1)
x <- rnorm(100)
y <- x+runif(100)
data <- data.frame(DV=y , IV=x)

tree <- party::ctree(DV ~ IV, data = data)
nodes(tree, unique(where(tree))) 

# [[1]]
# 3)*  weights = 19 

# [[2]]
# 6)*  weights = 26 

# [[3]]
# 9)*  weights = 19 

# [[4]]
# 8)*  weights = 19 

# [[5]]
# 5)*  weights = 17
Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • Thanks for pointing out that the code `nodes(tree, unique(where(tree)))` pertains to the old `party` as opposed to the new `partykit` package. However, transitioning to the newer `partykit` interface is highly recommended so I wouldn't recommend to downgrade to `party` just for using this old code snippet. – Achim Zeileis Mar 02 '18 at 13:30