在观星者中将多个模型相互重叠格式化 [英] Formatting multiple models on top of each other in stargazer

查看:48
本文介绍了在观星者中将多个模型相互重叠格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用stargazer(具有相同的因变量)将多个单变量模型输出彼此格式化,而我不能让它们不并排显示.

I want to format multiple univariate model outputs on top of one another using stargazer (with the same dependent variable), and I can't get them to not show up side-by-side.

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"在不同的模型上重复两次,我只希望它们每个一次,而不同的模型预测变量和估计相互之间.

Rather than having "versicolor" and "virginica" repeated twice for the different models, I just want each of them once, with the different model predictors and estimates underneath one another.

有什么办法吗?

推荐答案

starpolishr 可以完成面板格式模型输出的工作,但仅适用于 latex 对象,并且仅适用于平等的模型统计量.

starpolishr can do the job of panel format model outputs, but only for latex objects and only for equal model statistics.

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输出,如下所示:

Here you have to remove quotation marks and line numbering, and can compile as .tex Output looks like this:

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

It's still kind of a workaround and I cannot figure out a visual benefit of alignment model outputs in vertical/panel format. What you usually do is landscape your side-by-side tables in your final document.

这篇关于在观星者中将多个模型相互重叠格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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