当多个回归具有相同的 RHS 时,一次运行它们会更有效(请参阅使用多个 LHS 拟合线性模型)。例如,使用lm
and felm
:
library(lfe)
lm.fit.m <- lm(cbind(mpg, cyl) ~ gear, mtcars)
fe.fit.m <- felm(cbind(mpg, cyl) ~ gear | vs, mtcars)
我希望生成一个包含系数、标准误差以及报告的模型和样本汇总统计数据的结果表。那里有包装纸吗?
更新:失败的尝试
在通常使用一个 LHS var 的情况下,有很多选择。
lm.fit.s <- list(lm(mpg ~ gear, mtcars), lm(cyl ~ gear, mtcars))
fe.fit.s <- list(felm(mpg ~ gear | vs, mtcars), felm(cyl ~ gear | vs, mtcars))
观星者
library(stargazer)
stargazer(lm.fit.s, fe.fit.s, type = "text")
给出:
========================================================================================
Dependent variable:
---------------------------------------------------------------
mpg cyl mpg cyl
OLS OLS felm felm
(1) (2) (3) (4)
----------------------------------------------------------------------------------------
gear 3.923*** -1.193*** 2.930*** -0.823***
(1.308) (0.385) (1.023) (0.221)
Constant 5.623 10.585***
(4.916) (1.445)
----------------------------------------------------------------------------------------
Observations 32 32 32 32
R2 0.231 0.243 0.564 0.768
Adjusted R2 0.205 0.217 0.534 0.752
Residual Std. Error 5.374 (df = 30) 1.580 (df = 30) 4.114 (df = 29) 0.889 (df = 29)
F Statistic (df = 1; 30) 8.995*** 9.617***
========================================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
但stargazer
目前似乎不支持多 LHS 模型。
> stargazer(lm.fit.m)
Error in if (.global.coefficient.variables[i] %in% .global.intercept.strings) { :
argument is of length zero
> stargazer(fe.fit.m)
Error in summary.felm(object.name) :
Please specify lhs=[one of cbind(mpg, cyl).mpg,cbind(mpg, cyl).cyl]
特克斯雷格
library(texreg)
texreg::screenreg(c(lm.fit.s, fe.fit.s))
给出:
===============================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------
(Intercept) 5.62 10.59 ***
(4.92) (1.45)
gear 3.92 ** -1.19 ** 2.93 ** -0.82 ***
(1.31) (0.38) (1.02) (0.22)
---------------------------------------------------------------
R^2 0.23 0.24
Adj. R^2 0.21 0.22
Num. obs. 32 32 32 32
RMSE 5.37 1.58
R^2 (full model) 0.56 0.77
R^2 (proj model) 0.22 0.32
Adj. R^2 (full model) 0.53 0.75
Adj. R^2 (proj model) 0.17 0.28
===============================================================
*** p < 0.001, ** p < 0.01, * p < 0.05
但是对于多 LHS 如果也失败了:
> texreg::screenreg(lm.fit.m)
Error in validObject(.Object) :
invalid class “texreg” object: 1: invalid object for slot "coef.names" in class "texreg": got class "NULL", should be or extend class "character"
invalid class “texreg” object: 2: invalid object for slot "coef" in class "texreg": got class "NULL", should be or extend class "numeric"
invalid class “texreg” object: 3: invalid object for slot "se" in class "texreg": got class "NULL", should be or extend class "numeric"
invalid class “texreg” object: 4: invalid object for slot "pvalues" in class "texreg": got class "NULL", should be or extend class "numeric"
> texreg::screenreg(fe.fit.m)
Error in summary.felm(model) :
Please specify lhs=[one of cbind(mpg, cyl).mpg,cbind(mpg, cyl).cyl]