Re: [R] Re gression for loop test HELP! URGENT!
Hi Daniel, Thanks for the insight. My apologies for the unclearness of my original question. I have calculated the fit and se.fit values, see below predict(fm,newdata=test, se.fit=TRUE, type=c(response)) If I wasn't mistaking, this would give me the fit values and the standard errors. I just have one more question: based on my data, how might I calculate the expected value of M of the original data set, so that I could compare it to the M of all the data? Daniel Malter wrote: Hi, first, your initial statement of what you wanted to do was obviously ambiguous enough to confuse the responders. Therefore, clarity helps greatly in getting an accurate response. If I understand correctly, you have run ONE model on whatever data (also often called testing sample). Now you want to assess how well this ONE estimate derived from the testing sample predicts data from five (or any other arbitrary number of) holdout samples. In order to do that, the example I have provided works perfectly fine. The only thing you do not do is run multiple regressions in the first place. Instead you run only one initial regression on the testing sample and predict into the holdout samples. This, however, is only a slight change of the procedure I have outlined. The fit to the holdout samples is assessed with measures that any statistics/econometrics book deals with if it has a section on prediction. Best, 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: Monday, July 20, 2009 10:50 PM An: r-help@r-project.org Betreff: Re: [R] Re gression for loop test HELP! URGENT! I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm - lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest - lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: 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. 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}} __ 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
Re: [R] Re gression for loop test HELP! URGENT!
Hi Daniel, Thanks for the insight. My apologies for the unclearness of my original question. I have calculated the fit and se.fit values, see below predict(fm,newdata=test, se.fit=TRUE, type=c(response)) If I wasn't mistaking, this would give me the fit values and the standard errors. I just have one more question: based on my data, how might I calculate the expected value of M of the original data set, so that I could compare it to the M of all the data? Daniel Malter wrote: Hi, first, your initial statement of what you wanted to do was obviously ambiguous enough to confuse the responders. Therefore, clarity helps greatly in getting an accurate response. If I understand correctly, you have run ONE model on whatever data (also often called testing sample). Now you want to assess how well this ONE estimate derived from the testing sample predicts data from five (or any other arbitrary number of) holdout samples. In order to do that, the example I have provided works perfectly fine. The only thing you do not do is run multiple regressions in the first place. Instead you run only one initial regression on the testing sample and predict into the holdout samples. This, however, is only a slight change of the procedure I have outlined. The fit to the holdout samples is assessed with measures that any statistics/econometrics book deals with if it has a section on prediction. Best, 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: Monday, July 20, 2009 10:50 PM An: r-help@r-project.org Betreff: Re: [R] Re gression for loop test HELP! URGENT! I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm - lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest - lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: 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. 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}} __ 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
Re: [R] Re gression for loop test HELP! URGENT!
Hi r-help-boun...@r-project.org napsal dne 21.07.2009 09:18:51: Hi Daniel, Thanks for the insight. My apologies for the unclearness of my original question. I have calculated the fit and se.fit values, see below predict(fm,newdata=test, se.fit=TRUE, type=c(response)) If I wasn't mistaking, this would give me the fit values and the standard errors. I just have one more question: based on my data, how might I calculate the expected value of M of the original data set, so that I could compare it to the M of all the data? Maybe predict(fm) or fitted(fm) Regards Petr Daniel Malter wrote: Hi, first, your initial statement of what you wanted to do was obviously ambiguous enough to confuse the responders. Therefore, clarity helps greatly in getting an accurate response. If I understand correctly, you have run ONE model on whatever data (also often called testing sample). Now you want to assess how well this ONE estimate derived from the testing sample predicts data from five (or any other arbitrary number of) holdout samples. In order to do that, the example I have provided works perfectly fine. The only thing you do not do is run multiple regressions in the first place. Instead you run only one initial regression on the testing sample and predict into the holdout samples. This, however, is only a slight change of the procedure I have outlined. The fit to the holdout samples is assessed with measures that any statistics/econometrics book deals with if it has a section on prediction. Best, 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: Monday, July 20, 2009 10:50 PM An: r-help@r-project.org Betreff: Re: [R] Re gression for loop test HELP! URGENT! I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm - lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest - lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: 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. 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
Re: [R] Re gression for loop test HELP! URGENT!
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@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. __ 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.
Re: [R] Re gression for loop test HELP! URGENT!
Thanks Dr. Zuur for your reply. I've followed your suggestion, but it seems that this would only produce more regressions instead of use the one I produced originally to see if the original regression would fit new data? Is error analysis the only way i can make this happen? And how should I write it within the loop so that 5 rows can be iterated every time? Alain Zuur wrote: 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@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-tp24564236p24580748.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.
Re: [R] Re gression for loop test HELP! URGENT!
I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm - lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest - lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: 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. 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}} __ 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. - Regards, Richie. Mathematical Sciences Unit HSL -- View this message in context: http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24564236p24580889.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.
Re: [R] Re gression for loop test HELP! URGENT!
Hi, I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. So ... I haven't read the replies in this thread, but I'd be surprised if you haven't been directed to the predict function. The call to lm will return you an object of class lm. Calling predict on that object on *new* data will actually call the predict.lm function, and does exactly what it seems like you're asking to do, which is to fit new data. I think having a look through the documentation in ?predict.lm should make this clear, no? Is this what you're after? HTH, -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos __ 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.
Re: [R] Re gression for loop test HELP! URGENT!
Hi, first, your initial statement of what you wanted to do was obviously ambiguous enough to confuse the responders. Therefore, clarity helps greatly in getting an accurate response. If I understand correctly, you have run ONE model on whatever data (also often called testing sample). Now you want to assess how well this ONE estimate derived from the testing sample predicts data from five (or any other arbitrary number of) holdout samples. In order to do that, the example I have provided works perfectly fine. The only thing you do not do is run multiple regressions in the first place. Instead you run only one initial regression on the testing sample and predict into the holdout samples. This, however, is only a slight change of the procedure I have outlined. The fit to the holdout samples is assessed with measures that any statistics/econometrics book deals with if it has a section on prediction. Best, 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: Monday, July 20, 2009 10:50 PM An: r-help@r-project.org Betreff: Re: [R] Re gression for loop test HELP! URGENT! I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm - lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest - lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: 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. 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}} __ 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. - Regards, Richie. Mathematical Sciences Unit HSL -- View this message in context: http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24564236p 24580889.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] 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-tp24562766p24562766.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.
Re: [R] Re gression for loop test HELP! URGENT!
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.
Re: [R] Re gression for loop test HELP! URGENT!
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.