[R] Export summary from regression output

arun smartpink111 at yahoo.com
Wed Oct 24 06:29:21 CEST 2012


HI,
May be this helps:
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
      trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
      group <- gl(2,10,20, labels=c("Ctl","Trt"))
      weight <- c(ctl, trt)
      lm.D9 <- lm(weight ~ group)



fun1<-function(x){
     res<-c(paste(as.character(summary(x)$call),collapse=" "),
     x$coefficients[1],
     x$coefficients[2],
     length(x$model),
     summary(x)$coefficients[2,2],
     summary(x)$r.squared,
     summary(x)$adj.r.squared,
     summary(x)$fstatistic,
     pf(summary(x)$fstatistic[1],summary(x)$fstatistic[2],summary(x)$fstatistic[3],lower.tail=FALSE))
     names(res)<-c("call","intercept","slope","n","slope.SE","r.squared","Adj. r.squared",
     "F-statistic","numdf","dendf","p.value")
     return(res)}  
res2<-fun1(lm.D9)

write.csv(res2,"newregsummary.csv")
 

 x 
call lm weight ~ group 
intercept 5.032 
slope -0.371 
n 2 
slope.SE 0.3114348514 
r.squared 0.073077599 
Adj. r.squared 0.02158191 
F-statistic 1.4191012974 
numdf 1 
dendf 18 
p.value 0.249023166 

A.K.




----- Original Message -----
From: fxen3k <f.sehardt at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, October 23, 2012 7:28 AM
Subject: [R] Export summary from regression output

Hi there,

I tried it many times but didn't get it worked.

I just want to export the summary of a OLS regression (lm() function) into a
csv-file including the "call"-formula", "coefficients", "r-squared", "
adjusted r-squared"  and "f statistic". 

I know I can export:
write.csv2(Regression_60d_ann$coefficients, "Regression_60d_ann.csv")
But then I only get the coefficients, but not all the other output...

I tried creating a matrix and I wanted to put in
Regression_60d_ann$coefficients, Regression_60d_ann$adj.r.squared,
Regression_60d_ann$r.squared, etc. but it didn't work due to different
length of rows.


Can anyone help or has a better solution?

Thanks in advance
Felix



--
View this message in context: http://r.789695.n4.nabble.com/Export-summary-from-regression-output-tp4647109.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.





More information about the R-help mailing list