如何在观星计划中报告标准化模型?

发布于 2025-01-24 06:00:43 字数 2220 浏览 0 评论 0原文

我制作了以下简单的回归模型,并使用Stargazer输出绘制标准化与非标准化回归模型系数,标准误差和P值的表。

library(lm.beta)

mod <- lm(mpg ~ cyl + disp, mtcars)
summary(mod)
mod_std <- lm.beta(mod)
summary(mod_std)$coe[, 2]


library(stargazer)
stargazer(mod, mod_std, 
          coef = list(mod$coefficients, 
                      mod_std$standardized.coefficients),
          type='text')

这就是输出:

==========================================================
                                  Dependent variable:     
                              ----------------------------
                                          mpg             
                                   (1)            (2)     
----------------------------------------------------------
cyl                              -1.587**       -0.470    
                                 (0.712)        (0.712)   
                                                          
disp                             -0.021**      -0.423***  
                                 (0.010)        (0.010)   
                                                          
Constant                        34.661***        0.000    
                                 (2.547)        (2.547)   
                                                          
----------------------------------------------------------
Observations                        32            32      
R2                                0.760          0.760    
Adjusted R2                       0.743          0.743    
Residual Std. Error (df = 29)     3.055          3.055    
F Statistic (df = 2; 29)        45.808***      45.808***  
==========================================================
Note:                          *p<0.1; **p<0.05; ***p<0.01

如这里可以观察到的那样,标准化模型和非标准化的模型报道的标准误差(对于系数)是相同的。这是不正确的,因为标准误差应随着系数的标准化而改变。有没有办法报告正确的标准错误?还是如果没有,只需删除它们?

最后,从标准化到非标准化模型的变化是(系数)的显着性水平。这些不应改变,因为它们不受标准化的影响。有没有办法防止观星修改它们? P或P.Auto的论点可能会起作用,但我不知道如何使用它们。

LM.Beta的参考:Stefan Behrendt(2014)。 lm.Beta:向LM对象添加标准化的回归系数。 R软件包版本1.5-1。 https://cran.r-project.org/package = lm.beta

I made the following simple regression model and used stargazer to output a table that plots the standardized vs non-standardized regression model coefficients, standard errors and p-values.

library(lm.beta)

mod <- lm(mpg ~ cyl + disp, mtcars)
summary(mod)
mod_std <- lm.beta(mod)
summary(mod_std)$coe[, 2]


library(stargazer)
stargazer(mod, mod_std, 
          coef = list(mod$coefficients, 
                      mod_std$standardized.coefficients),
          type='text')

And this is the output:

==========================================================
                                  Dependent variable:     
                              ----------------------------
                                          mpg             
                                   (1)            (2)     
----------------------------------------------------------
cyl                              -1.587**       -0.470    
                                 (0.712)        (0.712)   
                                                          
disp                             -0.021**      -0.423***  
                                 (0.010)        (0.010)   
                                                          
Constant                        34.661***        0.000    
                                 (2.547)        (2.547)   
                                                          
----------------------------------------------------------
Observations                        32            32      
R2                                0.760          0.760    
Adjusted R2                       0.743          0.743    
Residual Std. Error (df = 29)     3.055          3.055    
F Statistic (df = 2; 29)        45.808***      45.808***  
==========================================================
Note:                          *p<0.1; **p<0.05; ***p<0.01

As can be observed here, the standard errors that are reported by the stargazer (for the coefficients) are the same for the standardized model and the non-standardized one. This is not correct as standard errors should change with the standardization of coefficients. Is there a way to report the correct standard errors? Or if not, simply remove them?

Lastly, what also changes from the standardized to the non-standardized models are the significance levels (of the coefficients). These should not change as they are not affected by standardization. Is there a way to prevent stargazer from modifying them? p or p.auto arguments maybe would work but I have no idea how to use them.

Reference for lm.beta: Stefan Behrendt (2014). lm.beta: Add Standardized Regression Coefficients to lm-Objects. R package version 1.5-1. https://CRAN.R-project.org/package=lm.beta

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情愿 2025-01-31 06:00:43

从系数开始时,您将需要手动输入每个模型的其他值, list 。标准化se =p =值(对于星星),以及GOFS( r 2 ) ,r 2 adj。,... ),在帮助页面中读取选项:?stargazer

但是,lm.beta似乎只添加了标准化系数,而没有计算出来。

使用公式 se*beta_star/beta/beta 来计算标准化的标准错误。

因此,您可以包装功能并计算它们,以便在Stargazer表中填充它们:

std_se <- \(x) x[, 'Std. Error']*x[, 'Standardized']/x[, 'Estimate']

std_se(summary(mod_std)$coefficients)
# (Intercept)         cyl        disp 
#   0.0000000   0.2109356   0.2109356 

但是,计算实际的标准化模型

mod_std2 <- lm(mpg ~ cyl + disp, as.data.frame(scale(mtcars)))
summary(mod_std2) |> getElement('coefficients')
#                Estimate Std. Error   t value     Pr(>|t|)
# (Intercept) 34.66099474 2.54700388 13.608536 4.022869e-14
# cyl         -1.58727681 0.71184427 -2.229809 3.366495e-02
# disp        -0.02058363 0.01025748 -2.006696 5.418572e-02

并将其放入以下方式肯定会更容易:

stargazer(mod, mod_std2, type='text')
# ==========================================================
#                                   Dependent variable:     
#                               ----------------------------
#                                           mpg             
#                                    (1)            (2)     
# ----------------------------------------------------------
# cyl                              -1.587**      -0.470**   
#                                  (0.712)        (0.211)   
                                                          
# disp                             -0.021*        -0.423*   
#                                  (0.010)        (0.211)   
                                                          
# Constant                        34.661***       -0.000    
#                                  (2.547)        (0.090)   
                                                          
# ----------------------------------------------------------
# Observations                        32            32      
# R2                                0.760          0.760    
# Adjusted R2                       0.743          0.743    
# Residual Std. Error (df = 29)     3.055          0.507    
# F Statistic (df = 2; 29)        45.808***      45.808***  
# ==========================================================
# Note:                          *p<0.1; **p<0.05; ***p<0.01

You would need to enter the additional values by hand, list-wise for each model, as you started with the coefficients. Standardized se=, the p= values (for the stars), ... as well as the the GOFs (R2, R2adj., ...), read options in help page: ?stargazer.

However, lm.beta appears to add nothing but the standardized coefficients, and none are yet calculated to report them.

Standardized standard errors are calculated using the formula SE*beta_star/beta.

So you could wrap a function, and calculate them, in order to fill them in the stargazer table:

std_se <- \(x) x[, 'Std. Error']*x[, 'Standardized']/x[, 'Estimate']

std_se(summary(mod_std)$coefficients)
# (Intercept)         cyl        disp 
#   0.0000000   0.2109356   0.2109356 

However, it might definitely be easier to calculate a actual standardized model

mod_std2 <- lm(mpg ~ cyl + disp, as.data.frame(scale(mtcars)))
summary(mod_std2) |> getElement('coefficients')
#                Estimate Std. Error   t value     Pr(>|t|)
# (Intercept) 34.66099474 2.54700388 13.608536 4.022869e-14
# cyl         -1.58727681 0.71184427 -2.229809 3.366495e-02
# disp        -0.02058363 0.01025748 -2.006696 5.418572e-02

and put that in:

stargazer(mod, mod_std2, type='text')
# ==========================================================
#                                   Dependent variable:     
#                               ----------------------------
#                                           mpg             
#                                    (1)            (2)     
# ----------------------------------------------------------
# cyl                              -1.587**      -0.470**   
#                                  (0.712)        (0.211)   
                                                          
# disp                             -0.021*        -0.423*   
#                                  (0.010)        (0.211)   
                                                          
# Constant                        34.661***       -0.000    
#                                  (2.547)        (0.090)   
                                                          
# ----------------------------------------------------------
# Observations                        32            32      
# R2                                0.760          0.760    
# Adjusted R2                       0.743          0.743    
# Residual Std. Error (df = 29)     3.055          0.507    
# F Statistic (df = 2; 29)        45.808***      45.808***  
# ==========================================================
# Note:                          *p<0.1; **p<0.05; ***p<0.01
清风夜微凉 2025-01-31 06:00:43

我设法制作了以下脚本:

stargazer(mod_std, 
          coef=list(mod_std$standardized.coefficients),
          se=list(summary(mod_std)$coe[, 2]),
          p=list(summary(mod)$coe[, 4]),
          type='text',
          omit.stat = c("all"),
          keep = c("cyl","disp"),
          report = c('vcp'), notes.append = FALSE,
          notes = "Coefficients are standardized")

随着以下输出:

===================================
           Dependent variable:     
      -----------------------------
                   mpg             
-----------------------------------
cyl              -0.470            
                p = 0.034          
                                   
disp             -0.423            
                p = 0.055          
                                   
===================================
===================================
Note: Coefficients are standardized

在这里,报告了标准化系数,以及原始模型的p值(应在标准化中不变)。

I managed to make the following script:

stargazer(mod_std, 
          coef=list(mod_std$standardized.coefficients),
          se=list(summary(mod_std)$coe[, 2]),
          p=list(summary(mod)$coe[, 4]),
          type='text',
          omit.stat = c("all"),
          keep = c("cyl","disp"),
          report = c('vcp'), notes.append = FALSE,
          notes = "Coefficients are standardized")

With the following output:

===================================
           Dependent variable:     
      -----------------------------
                   mpg             
-----------------------------------
cyl              -0.470            
                p = 0.034          
                                   
disp             -0.423            
                p = 0.055          
                                   
===================================
===================================
Note: Coefficients are standardized

Here, the standardized coefficients are reported, together with the p-values from the original model (which should be unchanged across standardization).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文