Hi everyone! I'm new to R, and I've sent this message as a non-member, but since it's pretty urgent, I'm sending it again now I'm on the mailing list (Thanks Daniel for your suggestion nevertheless). I have calculated a regression in the form of M ~ D + O + S, and I would like to take this regression and test it with other samples, 5 sets of M, D, O, and S at a time(I actually have 2000 sets, so it's probably not efficient to make each a separate set and then index). Since I'll need to test the regression for 400 groups, I thought a for loop might be necessary. I've put everything into a data frame already. Can anyone tell me how to write the code? I'm especially not sure about how to do the for loop. And then how would I calculate the error of how well the test samples fit the original regression? This is for my internship, so it's very urgent. THANKS A LOT!!!!! RBeginner [[alternative HTML version deleted]]
Richard.Cotton at hsl.gov.uk
2009-Jul-20 09:35 UTC
[R] Regression for loop test HELP! URGENT!
> I'm new to R, and I've sent this message as a non-member, but since it's > pretty urgent, I'm sending it again now I'm on the mailing list (Thanks > Daniel for your suggestion nevertheless). > > I have calculated a regression in the form of M ~ D + O + S, and I would > like to take this regression and test it with other samples, 5 sets ofM, D,> O, and S at a time(I actually have 2000 sets, so it's probably notefficient> to make each a separate set and then index). Since I'll need to test the > regression for 400 groups, I thought a for loop might be necessary. I'veput> everything into a data frame already. Can anyone tell me how to writethe> code? I'm especially not sure about how to do the for loop. > And then how would I calculate the error of how well the test samplesfit> the original regression? > This is for my internship, so it's very urgent.Take a deep breath, and think calm thoughts. Take a look at the posting guide (http://www.r-project.org/posting-guide.html) - it has useful ideas on thinking through your problem. If you can provide some code then we can see what you want more clearly. Show us how you've done your regression what form your data is in. Tell us which tests you'd like to do on the samples. If you are stuck with for loops, then take a look at section 9.2.2 in the Intro to R guide that comes with R. (Click Help -> Manuals -> an Introduction to R in RGui.) Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:22}}
Rbeginner wrote:> > Hi everyone! > I'm new to R, and I've sent this message as a non-member, but since it's > pretty urgent, I'm sending it again now I'm on the mailing list (Thanks > Daniel for your suggestion nevertheless). > > I have calculated a regression in the form of M ~ D + O + S, and I would > like to take this regression and test it with other samples, 5 sets of M, > D, > O, and S at a time(I actually have 2000 sets, so it's probably not > efficient > to make each a separate set and then index). Since I'll need to test the > regression for 400 groups, I thought a for loop might be necessary. I've > put > everything into a data frame already. Can anyone tell me how to write the > code? I'm especially not sure about how to do the for loop. > And then how would I calculate the error of how well the test samples fit > the original regression? > This is for my internship, so it's very urgent. > > > > > One option (out of the many): > > for (i in 1:2000) { > > M <- lm(M ~ D + O + S, subset = blah blah, data = YourData) > print(summary(M)) > } > > The "blah blah" select your rows of data for iteration i. > > See also: > > A Beginner's Guide to R (2009). Zuur, Ieno, Meesters. > > for something very similar. You can dump everything in a text file, or > just extract the required info from the summary function (like R^2 etc). > > Alain > > > Dr. Alain F. Zuur > First author of: > > 1. Analysing Ecological Data (2007). > Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p. > > 2. Mixed effects models and extensions in ecology with R. (2009). > Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer. > > 3. A Beginner's Guide to R (2009). > Zuur, AF, Ieno, EN, Meesters, EHWG. Springer > > > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24564236p24568726.html Sent from the R help mailing list archive at Nabble.com.