[R] ctree question

Achim Zeileis Achim.Zeileis at uibk.ac.at
Thu Jan 19 07:34:30 CET 2012

On Wed, 18 Jan 2012, seanstclair at verizon.net wrote:

>   Hello.  I have used the "party" package to generate a regression tree as
>   follows:
>   >origdata<-read.csv("origdata.csv")
>   >ctrl<-ctree_control(mincriterion=0.99,maxdepth=10,minbucket=10)
>   >test.ct<-ctree(Y~X1+X2+X3,data=origdata,control=ctrl)
>   The above works fine.  Orig data was my training data.  I now have a test
>   data file (testdata), and would like to run the testdata through the above
>   tree to see predictions.  I tried using the following function
>   >predict(test.ct,newdata=testdata)
>   but I get the following error:
>   Error in checkData(oldData, RET) :
>     Levels in factors of new data do not match original data
>   I've looked at the testdata file closely and it does not appear to contain
>   any levels of factors that were not in the original.

Did you check carefully enough? compare


and so on for X2 and X3. Maybe the _observed_ levels in the testdata are 
ok but not all levels.

>   What might I be doing
>   incorrectly, and how can i use the tree that was generated above to
>   generate predictions for this new file testdata?
>   THanks.
>   sean
> ______________________________________________
> 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.

More information about the R-help mailing list