[R] cross validation

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Jan 21 12:49:56 CET 2005


Dimitris Rizopoulos wrote:

> you could something like this (based on V&R's S Programming, pp. 175):
> 
> dat <- data.frame(matrix(rnorm(100*6), 100, 6))
> #####
> n <- nrow(dat)
> V <- 10 # number of folds
> samps <- sample(rep(1:V, length=n), n, replace=FALSE)
> #####
> # Using the first fold:
> train <- dat[samps!=1,] # fit the model
> test <- dat[samps==1,] # predict


Or see ?errorest in the "ipred" package.

Uwe Ligges


> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> ----
> Dimitris Rizopoulos
> Ph.D. Student
> Biostatistical Centre
> School of Public Health
> Catholic University of Leuven
> 
> Address: Kapucijnenvoer 35, Leuven, Belgium
> Tel: +32/16/336899
> Fax: +32/16/337015
> Web: http://www.med.kuleuven.ac.be/biostat
>     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
> 
> 
> ----- Original Message ----- From: "kolluru ramesh" <ramesh_k77 at yahoo.com>
> To: "Rpackage help" <r-help at stat.math.ethz.ch>
> Sent: Friday, January 21, 2005 11:19 AM
> Subject: [R] cross validation
> 
> 
>> How to select training data set and test data set from the original 
>> data for performing cross-validation
>>
>>
>> ---------------------------------
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
>>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.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