[R] printing out the summary for lm into a txt file
Hi All, I am trying to run several linear regressions and print out the summay and the anova reslts on the top of each other for each model. Below is a sample progarm that did not work. is it possible to print the anova below the summary of lm in one file? thanks for your help ## data-read.table(data.txt, header=T, sep='\t') for (i in 1:100){ y-data[,i] lm.model-lm(y~data$x1+data$x2+data$x3+data) sink(results.txt, append=T) s-summary(lm.Model) print(s) sink() an-anova(lm.Model) print(an) sink() } -- View this message in context: http://www.nabble.com/printing-out-the-summary-for-lm-into-a-txt-file-tp22062643p22062643.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] printing out the summary for lm into a txt file
did not work. Might that mean errors? Care to share? Running that through my wetware R interpreter, I think I am seeing you ask for creation of models with variable outcomes from a the first 100 columns of data. And then you are specifying a formula that includes a weird mixture of 3 vectors, data[,x1],x2 x3,... plus all of the data.frame, data? Have you tested this loop without the sink's to see if it produces anything meaningful? Once you test the process, then issue the sink(filename, append=TRUE) once, before the loop, do your analyses in the loop, and then close with sink() after the loop. -- David Winsemius On Feb 17, 2009, at 12:52 PM, kayj wrote: Hi All, I am trying to run several linear regressions and print out the summay and the anova reslts on the top of each other for each model. Below is a sample progarm that did not work. is it possible to print the anova below the summary of lm in one file? thanks for your help ## data-read.table(data.txt, header=T, sep='\t') for (i in 1:100){ y-data[,i] lm.model-lm(y~data$x1+data$x2+data$x3+data) sink(results.txt, append=T) s-summary(lm.Model) print(s) sink() an-anova(lm.Model) print(an) sink() } -- View this message in context: http://www.nabble.com/printing-out-the-summary-for-lm-into-a-txt-file-tp22062643p22062643.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] printing out the summary for lm into a txt file
The sink() command stops the sinking, so you send the lm output to the file, then stop the sinking before printing out the anova result. So the simplest thing to try is to put the first sink (with the filename and append=T) before you start the loop, remove all calls to sink within the loop, then do a single sink() after the loop ends. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of kayj Sent: Tuesday, February 17, 2009 10:52 AM To: r-help@r-project.org Subject: [R] printing out the summary for lm into a txt file Hi All, I am trying to run several linear regressions and print out the summay and the anova reslts on the top of each other for each model. Below is a sample progarm that did not work. is it possible to print the anova below the summary of lm in one file? thanks for your help ## data-read.table(data.txt, header=T, sep='\t') for (i in 1:100){ y-data[,i] lm.model-lm(y~data$x1+data$x2+data$x3+data) sink(results.txt, append=T) s-summary(lm.Model) print(s) sink() an-anova(lm.Model) print(an) sink() } -- View this message in context: http://www.nabble.com/printing-out-the- summary-for-lm-into-a-txt-file-tp22062643p22062643.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] printing out the summary for lm into a txt file
Thanks a lot for your help, it worked. Greg Snow-2 wrote: The sink() command stops the sinking, so you send the lm output to the file, then stop the sinking before printing out the anova result. So the simplest thing to try is to put the first sink (with the filename and append=T) before you start the loop, remove all calls to sink within the loop, then do a single sink() after the loop ends. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of kayj Sent: Tuesday, February 17, 2009 10:52 AM To: r-help@r-project.org Subject: [R] printing out the summary for lm into a txt file Hi All, I am trying to run several linear regressions and print out the summay and the anova reslts on the top of each other for each model. Below is a sample progarm that did not work. is it possible to print the anova below the summary of lm in one file? thanks for your help ## data-read.table(data.txt, header=T, sep='\t') for (i in 1:100){ y-data[,i] lm.model-lm(y~data$x1+data$x2+data$x3+data) sink(results.txt, append=T) s-summary(lm.Model) print(s) sink() an-anova(lm.Model) print(an) sink() } -- View this message in context: http://www.nabble.com/printing-out-the- summary-for-lm-into-a-txt-file-tp22062643p22062643.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/printing-out-the-summary-for-lm-into-a-txt-file-tp22062643p22065292.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] printing out the summary for lm into a txt file
this is the error message that I was getting In sink() ... : no sink to remove i got it to work . thanks for the help David Winsemius wrote: did not work. Might that mean errors? Care to share? Running that through my wetware R interpreter, I think I am seeing you ask for creation of models with variable outcomes from a the first 100 columns of data. And then you are specifying a formula that includes a weird mixture of 3 vectors, data[,x1],x2 x3,... plus all of the data.frame, data? Have you tested this loop without the sink's to see if it produces anything meaningful? Once you test the process, then issue the sink(filename, append=TRUE) once, before the loop, do your analyses in the loop, and then close with sink() after the loop. -- David Winsemius On Feb 17, 2009, at 12:52 PM, kayj wrote: Hi All, I am trying to run several linear regressions and print out the summay and the anova reslts on the top of each other for each model. Below is a sample progarm that did not work. is it possible to print the anova below the summary of lm in one file? thanks for your help ## data-read.table(data.txt, header=T, sep='\t') for (i in 1:100){ y-data[,i] lm.model-lm(y~data$x1+data$x2+data$x3+data) sink(results.txt, append=T) s-summary(lm.Model) print(s) sink() an-anova(lm.Model) print(an) sink() } -- View this message in context: http://www.nabble.com/printing-out-the-summary-for-lm-into-a-txt-file-tp22062643p22062643.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/printing-out-the-summary-for-lm-into-a-txt-file-tp22062643p22065365.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.