我正在尝试使用stargazer
两个单独的回归模型的结果创建一个回归表。我希望表格显示回归系数、95% 置信区间、t 值和 p 值,并且我已经做到了这一点:
library(stargazer)
data(iris)
attach(iris)
model1 <- lm(Sepal.Length ~ Petal.Length * Petal.Width)
model2 <- lm(Sepal.Width ~ Petal.Length * Petal.Width)
stargazer(model1, model2,
title="Results",
align=TRUE,
type = "text",
dep.var.labels=c("Sepal length","Sepal width"),
covariate.labels=c("Petal length","Petal width","Interaction"),
ci=TRUE,
report = "vcstp",
ci.level=0.95,
keep.stat="n",
model.numbers=FALSE,
notes = "",
notes.append = FALSE,
notes.label="",
digits = 2,
initial.zero = FALSE,
single.row=TRUE)
Results
===================================================
Dependent variable:
--------------------------------------
Sepal length Sepal width
---------------------------------------------------
Petal length .44 (.31, .57) -.37 (-.49, -.26)
t = 6.74 t = -6.22
p = 0.00 p = 0.00
Petal width -1.24 (-1.67, -.81) -.71 (-1.10, -.31)
t = -5.65 t = -3.51
p = 0.0000 p = .001
Interaction .19 (.12, .25) .22 (.16, .28)
t = 5.62 t = 7.13
p = 0.0000 p = 0.00
Constant 4.58 (4.36, 4.80) 4.04 (3.84, 4.24)
t = 40.89 t = 39.31
p = 0.00 p = 0.00
---------------------------------------------------
Observations 150 150
===================================================
但是,我希望每个模型的结果出现在 3 列中:一列带有系数和 CI,一列带有 t 值,1 列带有 p 值。
在下面的尝试中,我尝试使用该column.separate
函数为每个模型创建 3 列结果,然后使用系数、t 值和 p 值作为单独的输入,但我最终得到了 6 个表的输出,其中一个用于我想要的每个结果子集,而不是包含所有内容的 1 个表:
stargazer(summary(model1)$coefficients[,1], summary(model1)$coefficients[,3], summary(model1)$coefficients[,4], summary(model2)$coefficients[,1], summary(model2)$coefficients[,3], summary(model2)$coefficients[,4],
title="Results",
align=TRUE,
type = "text",
dep.var.labels=c("Sepal length","Sepal width"),
ci=TRUE,
report = "vcstp",
ci.level=0.95,
keep.stat="n",
model.numbers=FALSE,
notes = "",
notes.append = FALSE,
notes.label="",
digits = 2,
initial.zero = FALSE,
single.row=TRUE,
column.separate=c(3,3))
Results
=============================================================
(Intercept) Petal.Length Petal.Width Petal.Length:Petal.Width
-------------------------------------------------------------
4.58 .44 -1.24 .19
-------------------------------------------------------------
Results
=============================================================
(Intercept) Petal.Length Petal.Width Petal.Length:Petal.Width
-------------------------------------------------------------
40.89 6.74 -5.65 5.62
-------------------------------------------------------------
Results
=============================================================
(Intercept) Petal.Length Petal.Width Petal.Length:Petal.Width
-------------------------------------------------------------
0 0 0.0000 0.0000
-------------------------------------------------------------
Results
=============================================================
(Intercept) Petal.Length Petal.Width Petal.Length:Petal.Width
-------------------------------------------------------------
4.04 -.37 -.71 .22
-------------------------------------------------------------
Results
=============================================================
(Intercept) Petal.Length Petal.Width Petal.Length:Petal.Width
-------------------------------------------------------------
39.31 -6.22 -3.51 7.13
-------------------------------------------------------------
Results
=============================================================
(Intercept) Petal.Length Petal.Width Petal.Length:Petal.Width
-------------------------------------------------------------
0 0 .001 0
-------------------------------------------------------------
任何帮助将不胜感激!
更新:作者stargazer
通知我,目前(5.2 版,2015-07-14 发布),我所追求的格式无法使用stargazer
.