简体   繁体   English

在Stargazer表中包含标准化系数

[英]Include standardized coefficients in a Stargazer table

Forgive me as I'm brand new to R and if this is silly/easy, but I've been looking for hours but to no avail. 原谅我,因为我是R的新手,如果这很傻/容易,但我一直在找了几个小时,但无济于事。 I have a series of GLM models, and I'd like to report the standardized/reparametrized coefficients for each alongside the direct coefficients in a Stargazer table. 我有一系列的GLM模型,我想在Stargazer表中报告每个模型的标准化/重新参数化系数以及直接系数。 I created two separate models, one with standardized coefficients using the arm package. 我创建了两个单独的模型,其中一个模型使用arm包具有标准化系数。

require(arm)
model1 <- glm(...)
model1.2 <- standardize(model1)

Both models work, find and give the outputs I want, but I can't seem to figure out a way to get Stargazer to emulate this structure/look: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.699&rep=rep1&type=pdf 两种模型都能正常工作,找到并提供所需的输出,但是我似乎无法找出一种方法使Stargazer模仿这种结构/外观: http : //citeseerx.ist.psu.edu/viewdoc/download?doi = 10.1.1.65.699&rep = rep1&type = pdf

This can be done by asking stargazer to produce output for both models and making sure that the coefficients in the models have the same names so that stargazer knows that the standardized coefficient and the un-standardized coefficient should go on the same row. 这可以通过要求观星者为两个模型产生输出,并确保模型中的系数具有相同的名称来完成,以便观星者知道标准化系数和非标准化系数应该在同一行上。

The code below should help you get started. 以下代码将帮助您入门。

# generate fake data
x <- runif(100)
y <- rbinom(100, 1, x)

# fit the model
m1 <- glm(y~x, family = binomial())

# standardize it
m2 <- arm::standardize(m1)

# we make sure the coefficients have the same names in both models
names(m2$coefficients) <- names(m1$coefficients)

# we feed to stargazer
stargazer::stargazer(m1, m2, type = "text", 
                     column.labels = c("coef (s.e.)", "standarized coef (s.e.)"), 
                     single.row = TRUE)
#> 
#> ===========================================================
#>                              Dependent variable:           
#>                   -----------------------------------------
#>                                       y                    
#>                      coef (s.e.)    standarized coef (s.e.)
#>                          (1)                  (2)          
#> -----------------------------------------------------------
#> x                 4.916*** (0.987)     2.947*** (0.592)    
#> Constant          -2.123*** (0.506)      0.248 (0.247)     
#> -----------------------------------------------------------
#> Observations             100                  100          
#> Log Likelihood         -50.851              -50.851        
#> Akaike Inf. Crit.      105.703              105.703        
#> ===========================================================
#> Note:                           *p<0.1; **p<0.05; ***p<0.01

Created on 2019-02-13 by the reprex package (v0.2.1) reprex软件包 (v0.2.1)创建于2019-02-13

You can usually figure out how to achieve what you want from the output by diving into the stargazer help file and looking at this helpful webpage https://www.jakeruss.com/cheatsheets/stargazer/ 通常,您可以通过深入研究stargazer帮助文件并查看此有用的网页https://www.jakeruss.com/cheatsheets/stargazer/来找出如何从输出中实现所需的功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM