Search code examples
rrpart

Extra argument in rpart.plot and prp function not working for anova method: solution or alternative


I have an issue with the "extra" argument from the rpart.plot function. Basically, only "extra=1" works, all other numeric values from 2 to 4 throw an error. Using the mtcars dataset, here is the code I have that works:

  1. Creating the tree:

    library(rpart)
    library(rpart.plot)
    data("mtcars")
    
    mytree <- rpart(cyl ~ ., mtcars,control=rpart.control(minsplit=1, 
    minbucket=1, cp = 0.001), method = "anova")
    
  2. Ploting the tree, using either the rpart.plot or the prp function:

    rpart.plot(mytree, extra=1)
    prp(mytree, type=4, extra=1)
    

Now, changing the "extra=1" to "extra=2" (or 3, or 4) does not work. The error message I get is:

Error: extra=4 is illegal (for method="anova")

Now, I chose the "anova" method because the "class" method does not seem to be working with my dataset (R studio crashes basically) while the anova method works greatly.

  1. Can I solve this solution with the anova method ? If yes, how?
  2. Should I use another method and then understand why it crashes? The dataset I use is not crazy big so I have a hard time to see what I could do to solve this.

In advance thanks a lot for all the help !

Cheers, D.


Solution

  • As commented, "The extra=4 option only works for class models, because "probability per class of observations in the node" (to quote the rpart.plot help page) doesn't make sense for an anova model." So the problem is more why the class method is not working for my dataset.