0

I'm pretty sure my question doesn't totally make sense, but I'm trying to create a classification tree in R using 'rpart' and initially had the fit as something like:

fit <- rpart(success ~ A + B + C)

I have now realised 'success' might also be measured by another 'value'. So I was going to amend it to:

fit <- rpart(success + new_option ~ A + B + C)

But when I run these lines:

plot(fit, uniform=TRUE, main="Success plot")
text(fit, use.n = TRUE, all=TRUE, cex=.8)
post(fit, file = "tree.ps", title="Success plot")    

I get this error:

Error in plot.rpart(fit, uniform = TRUE, main = "Success plot") : 
fit is not a tree, just a root

So just wondering - is this even possible? Or do I need to tackle this in a totally different way?

halfer
  • 19,824
  • 17
  • 99
  • 186
dsnOwhiskey
  • 141
  • 1
  • 12
  • You can only model for one response variable, maybe you can try to combine `success` and `new_option` in a meaningful way to make this possible. – mtoto Sep 28 '16 at 08:07
  • try to fit the decision tree with a single response variable and you may use th 'cp' parameter in rpart control to grow a deeper (more complex) tree (choose small values of cp, e.g. cp=0.01). – Sandipan Dey Sep 28 '16 at 08:12
  • mtoto and sandipan - thanks for your advice - all good now. Cheers! – dsnOwhiskey Oct 03 '16 at 01:15

2 Answers2

1

This means that your tree algorithm has not created any splits. You can use the cp parameter to increase the complexity of your tree. the default value of cp is 0.01 so you can try 0.001. but note that this might imply you are over fitting your model.

p.s.. you can only have on response variable not var1 + var 2... if you need to combine both, do it before you insert it in to your modeling function.

RomRom
  • 302
  • 1
  • 11
  • Thanks! Tried 0.001 and it created more branches. Also, I ended up creating a new variable based on a simple if statement, so that should be good too now. Cheers! – dsnOwhiskey Oct 03 '16 at 01:14
0

For me it works when I write it as:

fit <- rpart(cbind(success, new_option) ~ A + B + C)
Martin Gal
  • 16,640
  • 5
  • 21
  • 39