Exporting and formatting regression analysis results in R to excel

佐手、 提交于 2019-12-13 05:20:57

问题


I am running regression analysis in R and unsure how to export my regression analysis results directly into Excel in standard regression table format (with significance level stars, standard errors, p-value, 95% confidence interval, R-sqr, F-test).

In stata, I would use the outreg2 command, which automatically generates a regression table, and I was wondering, if R has a similar code?

For example:

reg <- lm(imbd_score ~ budget 
+ duration 
+ year 
+ cast_total_facebook_likes, 
data = imbd)

summary(reg)

And then exporting this table into excel.


回答1:


I did the following, I don't know if there exists a smoother procedure, but the trick is to transform regression results in a data.frame object and then export them:

install.packages("outreg")
library("outreg")
table<-outreg(OLS, digits = 3L, alpha = c(0.1, 0.05, 0.01), 
       bracket = c("se"), starred = c("coef"), robust = FALSE, small = TRUE,
       constlast = FALSE, norepeat = TRUE)

install.packages("XLConnect")
library("XLConnect")
writeWorksheetToFile("yourdirectory/OLS.xlsx", 
                     data = table, 
                     sheet = "OLS", 
                     header = TRUE,
                     clearSheets = TRUE)

OLS is my object created by a lm regression.

Hope this can help,

Silvia D'Andrea



来源:https://stackoverflow.com/questions/49958828/exporting-and-formatting-regression-analysis-results-in-r-to-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!