【问题标题】:Formatting multiple models on top of each other in stargazer在 stargazer 中将多个模型相互叠加
【发布时间】:2019-12-03 17:10:36
【问题描述】:

我想使用 stargazer(具有相同的因变量)将多个单变量模型输出彼此叠加,但我无法让它们不并排显示。

data(iris)
stargazer(multinom(Species ~ Sepal.Length, data = iris),
          multinom(Species ~ Sepal.Width, data = iris),
          type = "text", apply.coef = exp, p.auto = FALSE, omit = "Constant")

它给出以下输出:

============================================================
                             Dependent variable:            
                  ------------------------------------------
                  versicolor virginica  versicolor virginica
                     (1)        (2)        (3)        (4)   
------------------------------------------------------------
Sepal.Length      123.479*** 941.955***                     
                   (0.907)    (1.022)                       

Sepal.Width                              0.002***  0.017*** 
                                         (0.991)    (0.844) 

------------------------------------------------------------
Akaike Inf. Crit.  190.068    190.068    260.537    260.537 
============================================================
Note:                            *p<0.1; **p<0.05; ***p<0.01

我不想让“versicolor”和“virginica”为不同的模型重复两次,我只希望它们中的每一个重复一次,不同的模型预测变量和估计值在彼此之下。

有没有办法做到这一点?

【问题讨论】:

  • 您希望模型统计信息是什么样的?在您的示例中,每个型号的 Akaike 都不同。这应该如何显示?并排是标准格式。

标签: r logistic-regression stargazer multinomial


【解决方案1】:

starpolishr 可以完成面板格式模型输出的工作,但仅适用于 latex 对象且仅适用于相等的模型统计信息。

install.packages("remotes")
remotes::install_github("ChandlerLutz/starpolishr")

## -- Regressoin example -- ##
library(stargazer)
data(mtcars)
##First set up models without weight
mod.mtcars.1 <- lm(mpg ~ hp, mtcars)
mod.mtcars.2 <- lm(mpg ~ hp + cyl, mtcars)
star.out.1 <- stargazer(mod.mtcars.1, mod.mtcars.2, keep.stat = "n")
##Second set of models with weight as a regressor
mod.mtcars.3 <- lm(mpg ~ hp + wt, mtcars)
mod.mtcars.4 <- lm(mpg ~ hp + cyl + wt, mtcars)
star.out.2 <- stargazer(mod.mtcars.3, mod.mtcars.4, keep.stat = c("n", "rsq"))

##stargazer panel -- same summary statistics across panels.
star.panel.out <- star_panel(star.out.1, star.out.2,
                             panel.names = c("Without Weight", "With Weight")
)
print(star.panel.out)

这里要去掉引号和行号,可以编译为.tex 输出如下:

这仍然是一种解决方法,我无法弄清楚垂直/面板格式的对齐模型输出的视觉优势。您通常做的是在最终文档中美化您的并排表格。

【讨论】:

    猜你喜欢
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 2018-09-28
    相关资源
    最近更新 更多