在单列中添加标准误差

在单列中添加标准误差

本文介绍了我可以使用 Stargazer 在单列中添加标准误差 * 和 * 置信区间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢 Stargazer,但在尝试将标准误差置信区间全部报告在一个表格中时遇到了一些问题.

将此简单回归视为可重现的示例:

set.seed(04152020)x 

我可以使用 ci 选项在两个单独的表中报告标准误差和置信区间,没有问题.

图书馆(观星者)# 标准错误观星者(m1,类型=文本")# 置信区间观星者(m1,ci = FALSE,类型=文本")

将它们放入单个表的解决方法是报告"模型两次,但随后不必要地重复系数.例如下面的代码:

stargazer(list(m1, m1),ci = c(假,真),类型 =文本")

产生:

==========================================================因变量:-----------------------------是(1) (2)----------------------------------------------------------× 1.981*** 1.981***(0.110) (1.766, 2.196)常数 -0.218** -0.218**(0.104) (-0.421, -0.014)----------------------------------------------------------观察 100 100R2 0.769 0.769调整后的 R2 0.766 0.766残留标准误差 (df = 98) 1.032 1.032F 统计量 (df = 1; 98) 325.893*** 325.893***==========================================================注:*p<0.1;** p<0.05;*** p

有没有办法将标准误置信区间自动放入一个列中,就像处理 p 值一样?例如.这段代码:

stargazer(m1,ci = c(假,真),报告 = ('vcsp'),类型 =文本")

产生我想要的,但使用 p 值,以及允许它的选项的文档 - report - 似乎只允许选择 p 值,如

你也可以做这样的疯狂事情,

I like Stargazer quite a bit but am running into some issues trying to report standard errors and confidence intervals all in a single table.

Consider this simple regression as a reproducible example:

set.seed(04152020)
x <- rnorm(100)
y <- 2*x + rnorm(100)
m1 <- lm(y~x)

I can report standard errors and confidence intervals in two separate tables no problem using the ci option.

library(stargazer)
# standard errors
stargazer(m1, type = "text")
# confidence intervals
stargazer(m1, ci = FALSE, type = "text")

A workaround to get them into a single table is to "report" the model twice, but then the coefficients are repeated unnecessarily. For example, the following code:

stargazer(list(m1, m1),
          ci = c(FALSE, TRUE),
          type = "text")

Produces:

==========================================================
                                  Dependent variable:
                              ----------------------------
                                           y
                                  (1)           (2)
----------------------------------------------------------
x                              1.981***       1.981***
                                (0.110)    (1.766, 2.196)

Constant                       -0.218**       -0.218**
                                (0.104)   (-0.421, -0.014)

----------------------------------------------------------
Observations                      100           100
R2                               0.769         0.769
Adjusted R2                      0.766         0.766
Residual Std. Error (df = 98)    1.032         1.032
F Statistic (df = 1; 98)      325.893***     325.893***
==========================================================
Note:                          *p<0.1; **p<0.05; ***p<0.01

Is there a way to put both standard errors and confidence intervals into a single column automatically, like you can do with p-values? E.g. this code:

stargazer(m1,
          ci = c(FALSE, TRUE),
          report = ('vcsp'),
          type = "text")

Produces exactly what I want, but with p-values, and the documentation for the option that allows for it—report—seems to only allow the choice for p-values, as indicated by this question and answer.

===============================================
                        Dependent variable:
                    ---------------------------
                                 y
-----------------------------------------------
x                              1.981
                              (0.110)
                             p = 0.000

Constant                      -0.218
                              (0.104)
                             p = 0.039

-----------------------------------------------
Observations                    100
R2                             0.769
Adjusted R2                    0.766
Residual Std. Error       1.032 (df = 98)
F Statistic           325.893*** (df = 1; 98)
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01
解决方案

I don't know how to do this in stargazer, but you can easily achieve the desired result with the modelsummary package. (Disclaimer: I am the author.) The

library(modelsummary)

set.seed(04152020)
x <- rnorm(100)
y <- 2*x + rnorm(100)
m1 <- lm(y~x)

modelsummary(m1, statistic = c("std.error", "conf.int"))

You can also do crazy things like this, as described on the website:

modelsummary(models, gof_omit = ".*",
             statistic = c("conf.int",
                           "s.e. = {std.error}",
                           "t = {statistic}",
                           "p = {p.value}"))

这篇关于我可以使用 Stargazer 在单列中添加标准误差 * 和 * 置信区间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:16