0

I just started using the R package Cubist which creates output like this:

Cubist [Release 2.07 GPL Edition] Tue Jul 09 19:46:48 2013

Target attribute `outcome'

Read 260 cases (9 attributes) from undefined.data

Model:

Rule 1: [26 cases, mean 0.3, range 0 to 8, est err 0.3]

if
    B4 <= 54.96766
    B7 > 39.66716
then
    outcome = 0

Rule 2: [48 cases, mean 0.3, range 0 to 8, est err 0.6]

if
    B1 > 56.99043
    B5 > 74.11118
    B6 > 155.996
then
    outcome = 9.1 - 0.17 B5 + 0.25 B7 + 0.15 NDVI

I can make use of the model using predict, but I would like to make a graphic of the tree. I don't see that it is possible looking at the manual, but I want to know if anyone knows of a way to do this.

agstudy
  • 119,832
  • 17
  • 199
  • 261
John
  • 336
  • 1
  • 4
  • 15
  • Just wanted to clarify, I am looking for a diagram like this: http://stackoverflow.com/questions/17460595/how-do-i-make-a-regression-tree-like-this – John Jul 10 '13 at 03:54

2 Answers2

1

You can use dotplot.cubist to get a visual view of the model conditions and coefficients. Here an example:

library(mlbench)
library(Cubist)
library(gridExtra)
data(BostonHousing)
mod1 <- cubist(x = BostonHousing[, -14], y = BostonHousing$medv)
summary(mod1)
p1 <- dotplot(mod1, what = "splits",main='Conditions')
p2 <- dotplot(mod1, what = "coefs",main='Coefs')
grid.arrange(p1,p2)

enter image description here

agstudy
  • 119,832
  • 17
  • 199
  • 261
  • good answer, but I should have clarified what kind of tree diagram I was looking for. It's in the comments below the question now. – John Jul 10 '13 at 04:02
0

rpart and partykit are both useful R packages for plotting tree style diagrams.

edit: see example of partykit here here

Community
  • 1
  • 1
jprockbelly
  • 1,533
  • 15
  • 30
  • As far as I could tell, rpart doesn't output regression formulas at the nodes, it only does mean values. I haven't looked into partykit, do you have a link to the graphics it can make? – John Jul 10 '13 at 04:07
  • [This give an example of how to use it](http://cran.r-project.org/web/packages/partykit/vignettes/partykit.pdf). Although on closer reading I think it may be quite similar to rpart. Added an example to my original answer – jprockbelly Jul 10 '13 at 06:52