[R] cross-validation in rpart

Allan Engelhardt allane at cybaea.com
Sat Mar 19 15:57:13 CET 2011


I assume you mean rpart::xpred.rpart ?  The beauty of R means that you 
can look at the source.  For the simple case (where xval is a single 
number) the code does indeed do simple random sampling

xgroups<- sample(rep(1:xval, length = nobs), nobs, replace = FALSE)


If you want another sampling, then you simply pass a vector as the xval 
parameter, as the documentation says: “This may also be an explicit list 
of integers that define the cross-validation groups”.

Hope this helps a little.

Allan

On 19/03/11 09:21, Penny B wrote:
> I am trying to find out what type of sampling scheme is used to select the 10
> subsets in 10-fold cross-validation process used in rpart to choose the best
> tree. Is it simple random sampling? Is there any documentation available on
> this?
>
> Thanks, Penny.



More information about the R-help mailing list