【问题标题】:Omit the constant and shift values into the correct location in stargazer in R在R中的stargazer中省略常量并将值移动到正确的位置
【发布时间】:2021-11-15 14:03:48
【问题描述】:

我想将平均边际效应输入到 R 中的 stargazer 表中。

问题在于 stargazer 将第一个边际效应值视为表中的常数。我计算的平均边际效应不包括常数。因此,我想从表中省略它。在 stargazer 中使用 omit 参数只是完全排除了该术语。因为它把第一个边际效应值当作常数,它实际上是降低了一个系数。

如何让 stargazer 忽略常数,同时让它识别出第一个值实际上是一个系数,而不是常数?

这是一个问题的例子:

#devtools::install_github("vincentarelbundock/marginaleffects")
library(marginaleffects)
library(stargazer)

Y <- sample(c(0,1), 1000, replace = T)
X <- sample(seq(1,50,1), 1000, replace = T)
Z <- sample(seq(1,50,1), 1000, replace = T)

DF <- data.frame(Y,X, Z)
Test <- glm(Y ~ X + Z, data = DF, family=binomial())
Test_DF <- data.frame(summary(marginaleffects(Test)))

Test_DF

#********************* Table **********************
#Fake Regression - to Make Table
Fake_RE <- glm(Y ~ X + Z, data = DF, family=binomial())

stargazer(list(Fake_RE), type = "text",
          coef = list(Test_DF$estimate),
          se = list(Test_DF$std.error))

平均边际效应:

> Test_DF
      type term     estimate   std.error statistic   p.value     conf.low    conf.high
1 response    X  0.001540192 0.001109148  1.388627 0.1649462 -0.000633697 0.0037140816
2 response    Z -0.001215714 0.001087828 -1.117561 0.2637546 -0.003347817 0.000916389

后续表:

> stargazer(list(Fake_RE), type = "text",
+           coef = list(Test_DF$estimate),
+           se = list(Test_DF$std.error))

=============================================
                      Dependent variable:    
                  ---------------------------
                               Y             
---------------------------------------------
X                           -0.001           
                            (0.001)          
                                             
Z                                            
                                             
                                             
Constant                     0.002           
                            (0.001)          
                                             
---------------------------------------------
Observations                 1,000           
Log Likelihood             -690.097          
Akaike Inf. Crit.          1,386.194         
=============================================
Note:             *p<0.1; **p<0.05; ***p<0.01

【问题讨论】:

    标签: r stargazer


    【解决方案1】:

    stargazer 包不正式支持这种类型的对象,并且由于该包自 2018 年以来没有更新,我认为期望很快得到支持是不合理的。

    如果您愿意考虑替代包,您可能想尝试the modelsummary package(免责声明:我是作者):

    #devtools::install_github("vincentarelbundock/marginaleffects")
    library(marginaleffects)
    library(modelsummary)
    
    Y <- sample(c(0,1), 1000, replace = T)
    X <- sample(seq(1,50,1), 1000, replace = T)
    Z <- sample(seq(1,50,1), 1000, replace = T)
    
    DF <- data.frame(Y,X, Z)
    Test <- glm(Y ~ X + Z, data = DF, family=binomial())
    mfx <- marginaleffects(Test)
    
    modelsummary(mfx)
    
    Model 1
    X 0.000
    (0.001)
    Z 0.002
    (0.001)
    Num.Obs. 1000
    AIC 1389.3
    BIC 1404.0
    Log.Lik. -691.653

    【讨论】:

    • 太棒了!非常感谢您的洞察力。对此,我真的非常感激。我会试试modelsummary 包。
    猜你喜欢
    • 1970-01-01
    • 2021-12-15
    • 2023-01-03
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多