[EMAIL PROTECTED] (Cornilia) wrote: > I have a training data set, and I want to obtain the LOOCV error rate > for a linear regression model. How can I implement this in R or > S-Plus? I can use for loop and fit linear models n times, with one row > out each time. My main problem is that I don't know how to leave one > row out of my data set in lm function within the for loop. [...]
In the S language, a negative index means "all but this index". Let's say X is a matrix. Then X[-i,] is all rows except the i'th row. (The missing column index means "all columns".) But do you really need to do that? If I recall correctly there is a formula for the leave-one-out cross-validation error. Or maybe I'm thinking of the so-called generalized cross-validation error. Sorry, I'm too lazy to go look it up right now. You might look at the contributed packages at: http://www.r-project.org I wouldn't be surprised if someone has already put something together for cross-validation. BTW it is a good idea to spell out abbreviations; you want as many people as possible to understand the question. YMMV. For what it's worth, Robert Dodier . . ================================================================= Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at: . http://jse.stat.ncsu.edu/ . =================================================================
