[R] Error when I try to build / plot a tree using rpart()

Liaw, Andy andy_liaw at merck.com
Sat Jun 12 03:25:31 CEST 2004


You didn't get a tree.  The output of print() tells you that you only have
the root node.  You may need to adjust some of the parameters with
rpart(..., control=rpart.control(...)).  See ?rpart.control.

HTH,
Andy

> From: Jude Ryan
> 
> Hi,
> 
> I am using the rpart package to build a classification tree. I did 
> manage to build a tree with data on a previous project. However, when 
> attampting to build a tree on a project I am working on, I seem to be 
> getting the error shown below:
> 
>  > nhg3.rp <- rpart(profitresp ~., nhg3, method="class")
>  > plot(nhg3.rp, branch=0.4, uniform=T); text(nhg3.rp, digits=3)
> Error in yval[, 1] : incorrect number of dimensions
> 
> The distribution of my binary dependent variable is:
>  > table(nhg$profitresp)
> 
>    0    1
> 3703 4360
> 
> I am using 105 potential predictor variables. I am trying to come up 
> with a decision rule to identify profitable responders from 
> non-responders to a mailing.
> 
> Some other details are:
>  > summary(nhg3.rp)
> Call:
> rpart(formula = profitresp ~ ., data = nhg3, method = "class")
>   n= 8063
> 
>            CP nsplit rel error
> 1 0.009451796      0         1
> Error in yval[, 1] : incorrect number of dimensions
> 
>  > print(nhg3.rp)
> n= 8063
> 
> node), split, n, loss, yval, (yprob)
>       * denotes terminal node
> 
> 1) root 8063 3703 1 (0.4592583 0.5407417) *
> 
>  > printcp(nhg3.rp)
> 
> Classification tree:
> rpart(formula = profitresp ~ ., data = nhg3, method = "class")
> 
> Variables actually used in tree construction:
> character(0)
> 
> Root node error: 3703/8063 = 0.45926
> 
> n= 8063
> 
>          CP nsplit rel error
> 1 0.0094518      0         1
> 
> Any help is appreciated.
> 
> Thanks much,
> 
> Jude Ryan
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list