如何覆盖p值并删除星际式包装中的标准错误?

发布于 2025-01-23 09:35:03 字数 3157 浏览 3 评论 0原文

我试图覆盖星际包装显示的P值及其显着性水平。

使用此简单模型(从下面引用的“ sjplot”软件包取):

data(efc)
library(sjPlot)

# fit a model
fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)

# plot model
plot_models(fit1, std.est = "std", show.p  = TRUE, p.shape =TRUE, grid = TRUE)

“在此处输入图像描述”

现在我想使用表中的Stargazer中与此图相关的结果。 为此,我将获得标准化的系数(使用下面引用的lm.Beta):

library(lm.beta)
fit1_std = lm.beta(fit1)

现在我正在制作表,并且我指定我想使用标准化的系数:

stargazer(fit_1_std, 
          coef = list(fit_1_std$standardized.coefficients),
          type='text')

它具有输出:

===============================================
                        Dependent variable:    
                    ---------------------------
                             barthtot          
-----------------------------------------------
c160age                       -0.100           
                              (0.071)          
                                               
c12hour                      -0.477***         
                              (0.019)          
                                               
c161sex                       -0.004           
                              (2.086)          
                                               
c172code                      -0.016           
                              (1.420)          
                                               
Constant                       0.000           
                              (6.172)          
                                               
-----------------------------------------------
Observations                    821            
R2                             0.270           
Adjusted R2                    0.266           
Residual Std. Error      25.353 (df = 816)     
F Statistic           75.284*** (df = 4; 816)  
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01

在这里,系数看起来正确。它们与图中的标准化系数相同。但是,查看p值:它们绝对不同。

看着《森林情节》中重要的“职业时代”,突然在星际合伙人提供的桌子上不再重要了。此外,标准误差是原始模型的误差(不再对应于标准化系数)。

如何删除标准错误并使用正确的p值?换句话说,如何使我的观星桌子准确地反映了“ plot_model”图中显示的内容?

我尝试了这样的事情,其中​​我将手动添加P值并尝试删除标准错误:

stargazer(fit_1_std, 
          coef = list(fit_1_std$standardized.coefficients),
          p = list(c(0.0019),c(<2e-16),c(0.9002),c(0.5915)), se = FALSE, 
          type='text')

但是它不起作用。

引用lm.beta: https:https://cran.r -project.org/web/packages/lm.beta/lm.beta.pdf 引用sjplot: https:// https://cran.r-project.org/web/web/web/web/web/web/web/web/web/web/web/web/web/web/web/web/web = /packages/sjplot/index.html

I am trying to override the p-values that are displayed by stargazer package and its significance levels.

Using this simple model (taken from the "SjPlot" package, referenced below):

data(efc)
library(sjPlot)

# fit a model
fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)

# plot model
plot_models(fit1, std.est = "std", show.p  = TRUE, p.shape =TRUE, grid = TRUE)

This creates:

enter image description here

Now I want to report the results associated with this plot in stargazer using a table.
To do this, I will obtain the standardized coefficients (using lm.beta referenced below):

library(lm.beta)
fit1_std = lm.beta(fit1)

Now I am making the table, and I am specifying I want to use the standardized coefficients:

stargazer(fit_1_std, 
          coef = list(fit_1_std$standardized.coefficients),
          type='text')

Which has the output:

===============================================
                        Dependent variable:    
                    ---------------------------
                             barthtot          
-----------------------------------------------
c160age                       -0.100           
                              (0.071)          
                                               
c12hour                      -0.477***         
                              (0.019)          
                                               
c161sex                       -0.004           
                              (2.086)          
                                               
c172code                      -0.016           
                              (1.420)          
                                               
Constant                       0.000           
                              (6.172)          
                                               
-----------------------------------------------
Observations                    821            
R2                             0.270           
Adjusted R2                    0.266           
Residual Std. Error      25.353 (df = 816)     
F Statistic           75.284*** (df = 4; 816)  
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01

Here, the coefficients look right. They are the same standardized coefficients as in the plot. However, looking at the p-values: they are definitely different.

Looking at "career's age", which was significant in the forest plot, it suddenly is not significant anymore in the table provided by the stargazer. Further, the standard errors are the ones from the original model (not corresponding to the standardized coefficients anymore).

How could I remove the standard errors and use the correct p-values? In other words, how can I make my stargazer table reflect exactly what is shown in the "plot_model" figure?

I tried something like this, in which I would manually add the p-values and try to remove the standard errors:

stargazer(fit_1_std, 
          coef = list(fit_1_std$standardized.coefficients),
          p = list(c(0.0019),c(<2e-16),c(0.9002),c(0.5915)), se = FALSE, 
          type='text')

But it did not work.

Citation lm.beta: https://cran.r-project.org/web/packages/lm.beta/lm.beta.pdf
Citation sjPlot: https://cran.r-project.org/web/packages/sjPlot/index.html

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

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

发布评论

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

评论(1

满栀 2025-01-30 09:35:03

我认为默认情况下,估计值在估计下显示什么是误解,即标准错误。您可以使用Report选项将它们变成P值。无需替代手册。

data(efc)
library(sjPlot)

# fit a model
fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)

summary(fit1)

stargazer(fit1, type="text", report = "vs*p")

===============================================
                        Dependent variable:    
                    ---------------------------
                             barthtot          
-----------------------------------------------
c160age                     (0.071)***         
                             p = 0.002         
                                               
c12hour                     (0.019)***         
                             p = 0.000         
                                               
c161sex                       (2.086)          
                             p = 0.901         
                                               
c172code                      (1.420)          
                             p = 0.592         
                                               
Constant                    (6.172)***         
                             p = 0.000         
                                               
-----------------------------------------------
Observations                    821            
R2                             0.270           
Adjusted R2                    0.266           
Residual Std. Error      25.353 (df = 816)     
F Statistic           75.284*** (df = 4; 816)  
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01

I think there is a misunderstanding of what stargazer show underneath estimates by default, i.e. the standard errors. You can turn them into p-values with the report option. No need to substitute something manual.

data(efc)
library(sjPlot)

# fit a model
fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)

summary(fit1)

stargazer(fit1, type="text", report = "vs*p")

===============================================
                        Dependent variable:    
                    ---------------------------
                             barthtot          
-----------------------------------------------
c160age                     (0.071)***         
                             p = 0.002         
                                               
c12hour                     (0.019)***         
                             p = 0.000         
                                               
c161sex                       (2.086)          
                             p = 0.901         
                                               
c172code                      (1.420)          
                             p = 0.592         
                                               
Constant                    (6.172)***         
                             p = 0.000         
                                               
-----------------------------------------------
Observations                    821            
R2                             0.270           
Adjusted R2                    0.266           
Residual Std. Error      25.353 (df = 816)     
F Statistic           75.284*** (df = 4; 816)  
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文