1

I am trying to generate the information depicted in Plot 1, more specifically the percentage and confidence interval on the paths. Plot 2 is what I am getting when running the syntax bellow. I am sorry if this is too basic, but I am really struggling to find the correct syntax. Many thanks!

library(partykit)

IG.tree = ctree(total_factor  ~ IGCDS9_1 + IGCDS9_2 + IGCDS9_3 + IGCDS9_4 + 
IGCDS9_5 + IGCDS9_6 + IGCDS9_7 + IGCDS9_8 + IGCDS9_9, 
data = data)

plot(IG.tree) 

Plot1 Plot 1

Plot2 Plot 2

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58

1 Answers1

0

The plot you are looking for is not available out of the box. But at least text with relative frequencies for the bars in the barplot have been added recently: Plot party decision tree

However, this also will need adaptation for the layout that you are after. But you can set up your own functions for terminal_panel and inner_panel that do exactly what you want. I would recommend to start out by copying the source code of node_barplot and node_inner from the partykit source package and adapt this to do what you want.

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • I was wondering about the path estimates displayed in plot1. Perhaps the authors were using another package other than partykit or using a specific a specific source code to obtain those values. Would you know how to access such estimates? – Bruno Śnski Jul 30 '17 at 11:39
  • The plot looks very much like coming from partykit. All information displayed can be computed within the package. But I would recommend to contact the authors directly... – Achim Zeileis Jul 30 '17 at 11:44
  • Indeed, it looks like partykit. I will drop them an email, if I get a solution I will post it here. – Bruno Śnski Jul 30 '17 at 17:33
  • Hi again, Achim. Forgetting a little about the plot, but getting into calculation. So far I could not figure it out how to get the additional output displayed for each split in plot 1 (e.g., yes 44.75%[CI]). Everywhere I read, the outputs are just the standard split yes/no or a given score, as in plot 2 (e.g., >4). Would you please give a hand on how to obtain these additional information? Many thanks! – Bruno Śnski Aug 07 '17 at 17:22
  • Well, that branch of the tree has overall `n <- 64 + 52 + 65` observations. The proportion of "successes" in the response is `p <- (1 + 22 + 58) / n`. The standard deviation is `s <- sqrt(p * (1 - p)/n)`. And then normal quantiles used as critical values are `q <- qnorm(c(0.5, 0.025, 0.975))`. And then you can put everything together and compute the mean and confidence interval in percent as `100 * (p + q * s)`. – Achim Zeileis Aug 07 '17 at 21:56