Re: [R] rpart error when constructing a classification tree

From: Randy Griffiths <rgriff77_at_gmail.com>
Date: Mon, 4 Feb 2008 09:17:18 -0700

Sorry, I wasn't very helpful. Let me try this again. I have attached a subsample of the data which still gives me the same error as when I use the full data file. I am trying to make a decision tree using rpart. This is my code and output.
> data <- read.table("/Users/randygriffiths/Desktop/data", header=T)
> attach(data)
>
> library(rpart)
> bookings.cart <- rpart(totalRev~., data=data, method="class")
> bookings.cart
n= 50

node), split, n, loss, yval, (yprob)

  CP nsplit rel error
1 0 0 1
Error in yval[, 1] : incorrect number of dimensions

I have used rpart on past projects without any problems. I can do a regression tree without any error as well (by leaving off the method="class" argument). I have used this same data using 'randomForest' with good results and also using 'tree' without this error. I have seen that at least a few people have reported getting this same error with rpart, but I could not find an answer that helped the problem. Can anyone help me?

Randy

On Jan 30, 2008 2:33 AM, Uwe Ligges <ligges_at_statistik.tu-dortmund.de> wrote:

>
>
> Randy Griffiths wrote:
> > I am trying to make a decision tree using rpart. The function runs very
> > quickly considering the size of the data (1742, 163). When I call the
> > summary command I get this:
> >
> >> summary(bookings.cart)
> > Call:
> > rpart(formula = totalRev ~ ., data = bookings, method = "class")
> > n=1741 (1 observation deleted due to missingness)
> >
> > CP nsplit rel error
> > 1 0 0 1
> > Error in yval[, 1] : incorrect number of dimensions
> >
>
>
> And we get:
>
> R> summary(bookings.cart)
> Error in summary(bookings.cart) : object "bookings.cart" not found
>
> hence we cannot reproduce and inspect your problem. Please read the
> posting guide.
>
> Uwe Ligges
>
>
> > note:
> >> dim(bookings)
> > [1] 1742 163
> >
> >
> > I have run rpart on past projects without any problems. I have used a
> > catagorical version of the variable totalRev that was partitioned into
> four
> > levels (and coded as a factor).
> > I tried making a tree with the tree command (in the 'tree' package) and
> was
> > able to construct a tree without any errors. However, I would much
> rather
> > use rpart.
> >
> > Does anyone have any ideas that might help?
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help_at_r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 04 Feb 2008 - 16:24:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 04 Feb 2008 - 16:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive