Thanks for the suggestion, but I think I might not have made myself very clear. I actually have about 2000 sets of M, D, O, and S, so it's probably not efficient to make each a separate set and then index. I've put everything into a data frame, so I would like to test how well the regression fit for each group, which consists of 5 sets of M, D, O, and S. Since I'll need to test it for about 400 groups, I thought a for loop might be necessary. Any suggestions? I'm just not especially sure how to do the for loop.
Daniel Malter wrote: > > for a beginner, it's probably even easier to it by hand if it is just five > datasets. > > bind the 5 datasets together in one dataset and create and index variable > (1 > to 5) for each of the observations according to the dataset the > obersvation > comes from > > then run five regressions using > > reg1=lm(M~D+O+S,subset=c(index==1)) > . > . > . > reg5=lm(M~D+O+S,subset=c(index==5)) > > and then predict from each regression > > predict(reg1,newdata=data.frame(D,O,S)) > . > . > . > predict(reg5,newdata=data.frame(D,O,S)) > > You can then assess how well the prediction from each of the datasets fits > the respective other datasets... > > Daniel > > ------------------------- > cuncta stricte discussurus > ------------------------- > > -----Ursprüngliche Nachricht----- > Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im > Auftrag von Rbeginner > Gesendet: Sunday, July 19, 2009 9:49 PM > An: r-help@r-project.org > Betreff: [R] Re gression for loop test HELP! URGENT! > > > Hi everyone! > I'm new to R, and I'm stuck on a problem I don't know how to approach. > 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 at a time(5 > meaning 5 set, each consisting M, D, O, and S of a specific date). I > assume > I'll need a for loop. Right now, My data of M, D, O, and S are all stored > in > separate txt files, but should I just put them into a table or something? > 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 > -- > View this message in context: > http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24562766p > 24562766.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > > ______________________________________________ > R-help@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-tp24562766p24563579.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.