0

I want to change the splitting method in rpart function from "gini" (which is default) to "information".

In the help section we have this example:

fit2 <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
              parms = list(prior = c(.65,.35), split = "information"))

in method argument details we have: "Alternatively, method can be a list of functions named init, split and eval. Examples are given in the file ‘tests/usersplits.R’ in the sources, and in the vignettes ‘User Written Split Functions"

and in the parms argument details: "The splitting index can be gini or information. The default priors are proportional to the data counts, the losses default to 1, and the split defaults to gini."

When I try to create the model:

model<-rpart(as.factor(char)~., data=train, split = "information")
Error: ***Argument split not matched***

I find this (and most of the) R help sections not very clear. Apparently I do not have the information option. Am I supposed to define the function for split before and then build my model?, or also input the probabilities vector? How can I use information like in the example?

Nate
  • 10,361
  • 3
  • 33
  • 40
itsame
  • 1
  • 1
  • 1
    If you indent your code lines by 4 spaces they will format properly. – G. Grothendieck Dec 09 '16 at 00:25
  • It's a fairly clear error message. You tried to give `rpart` a parameter named `split` and there is no such parameter on the help page. Items on the left hans side of the Arguments section can be given as arguments. Or if you decide to use the "three dots" mechanism, you can look at the Arguments section of rpart.control, which also has no split argument listed. The `split` you are seeing in the example is just one element in a list given to `parms`. – IRTFM Dec 09 '16 at 01:15

1 Answers1

2

You did not faithfully reproduce the example. I think that what you want is

model<-rpart(as.factor(char)~., data=train, parms=list(split = "information"))
G5W
  • 36,531
  • 10
  • 47
  • 80