0

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

1 Answers1

1

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
Marco
  • 2,368
  • 6
  • 22
  • 48
  • Hi @Marco, is it possible to have p-values in the parentheses instead of being denoted as "p = ...." and having to change them manually? Thanks – fsure Aug 02 '23 at 07:02
  • 1
    I think there is no easy way. You can go and edit the source code of the function before calling it and change the style to anything you like. See https://stackoverflow.com/questions/42995868/r-stargazer-package-eliminate-t-label-from-reported-test-statistics Alternative: Check out the `modelsummary` package. – Marco Aug 02 '23 at 07:12