将统计信息分成多个列

时间:2015-08-14 19:44:21

标签: r stargazer

我尝试使用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值,另一个包含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无法实现我所遵循的格式。

0 个答案:

没有答案