将R中的回归分析结果导出并格式化为excel [英] Exporting and formatting regression analysis results in R to excel

查看:2682
本文介绍了将R中的回归分析结果导出并格式化为excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中运行回归分析,不确定如何将回归分析结果以标准回归表格式直接导出到Excel中(具有显着性星号,标准误差,p-value,95%置信区间,R-sqrF-test).

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

在统计中,我会使用outreg2命令,该命令会自动生成一个回归表,我想知道R是否具有类似的代码?

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

例如:

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

summary(reg)

然后将此表导出到excel中.

And then exporting this table into excel.

推荐答案

我做了以下事情,我不知道是否存在更平滑的过程,但诀窍是将回归结果转换为data.frame对象,然后导出它们:

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是我通过lm回归创建的对象.

OLS is my object created by a lm regression.

希望这会有所帮助,

Silvia D'Andrea

Silvia D'Andrea

这篇关于将R中的回归分析结果导出并格式化为excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆