As John suggests, more information and some sample data would help. I
haven't used loocv, but here is a simple example of leave one out cross
validation with simple linear regression. This does not eliminate the loop, but
uses lapply() which makes specifying the loop simpler. The results of the 40
regressions are stored in a list called results and results.coef contains the
intercept and slope for each regression in a matrix.
> set.seed(42)
> x <- rnorm(40, 10, 2)
> y <- x + rnorm(40, 0, 2)
> results <- lapply(1:40, function(i) lm(y[-i] ~ x[-i]))
> results.coef <- t(sapply(results, coef))
> summary(results.coef)
(Intercept) x[-i]
Min. :-0.1477 Min. :0.8408
1st Qu.: 0.2032 1st Qu.:0.9830
Median : 0.2613 Median :0.9883
Mean : 0.2933 Mean :0.9866
3rd Qu.: 0.3240 3rd Qu.:0.9959
Max. : 1.9160 Max. :1.0245
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of John Kane
Sent: Monday, July 6, 2015 6:53 PM
To: Vyshnnavi Parthasarathy; r-help at r-project.org
Subject: Re: [R] Leave one out procedure - R
Hi Vyshnnavi,
I'd suggest having a look at
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
and http://adv-r.had.co.nz/Reproducibility.html for some hints on how to ask
questions on the R-help List.
At the moment I don't think you have supplied enough information, code, and
data for people to easily answer your questions.
BTW if you are supplying sample data the best way is to use the dput() function.
It provides an exact copy of the data set that you are working with.
Sorry not to be of any substantive help.
John Kane
Kingston ON Canada
> -----Original Message-----
> From: vyshnnaviammu at gmail.com
> Sent: Mon, 6 Jul 2015 08:56:52 -0700
> To: r-help at r-project.org
> Subject: [R] Leave one out procedure - R
>
> Hello,
> I am still in the process of familiarizing myself with R, pardon me if
> this
> is basic. I want to run a leave one out procedure for a 40 member
> dataset.
> At the moment I am doing it via a simple for loop. I wanted to know if
> there is a superior way to do it. I read about the loocv command here -
> http://artax.karlin.mff.cuni.cz/r-help/library/DMwR/html/loocv.html.
> Since
> I need to save the output generated in each iteration, I am not very sure
> how exactly to implement the same using the loocv command. If you could
> give me an insight into how to do it/ suggest quicker ways to do leave
> one
> out cross validation, it would be really helpful!
>
> Thanks,
> Vyshnnavi
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
____________________________________________________________
GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email to find out more!
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.