0

I was following the instructions on this page: https://strengejacke.github.io/ggeffects/articles/practical_robustestimation.html

I did a basic regression without robust standard errors:

data(mtcars)
reg <- glm(vs ~ mpg + cyl + disp + hp, mtcars, family="binomial")
screenreg(reg)

Then I got the predicted values:

> ggpredict(reg, "mpg")
Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth plots.
# Predicted probabilities of vs

mpg | Predicted |       95% CI
------------------------------
 10 |      0.70 | [0.02, 1.00]
 12 |      0.61 | [0.03, 0.99]
 16 |      0.39 | [0.05, 0.89]
 20 |      0.21 | [0.03, 0.70]
 22 |      0.15 | [0.01, 0.70]
 24 |      0.10 | [0.00, 0.74]
 28 |      0.05 | [0.00, 0.86]
 34 |      0.01 | [0.00, 0.96]

Adjusted for:
*  cyl =   6.19
* disp = 230.72
*   hp = 146.69

Say I wanted robust standard errors. I'm able to do this through coeftest and alter the screenreg output accordingly:

reg2 <- coeftest(reg, vcov = vcovHC, type = "HC1", cluster = "ResponseId")

screenreg(list(reg),
          override.se=list(
            reg2[,2]),
          override.pvalues=list(
            reg2[,4]))

However, when it came time to look at the predicted values in consideration of the robust standard errors, the values are exactly the same.

ggpredict(reg, "mpg", vcov_fun = "vcovHC", vcov_type = "HC1")
Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth plots.
# Predicted probabilities of vs

mpg | Predicted |       95% CI
------------------------------
 10 |      0.70 | [0.02, 1.00]
 12 |      0.61 | [0.03, 0.99]
 16 |      0.39 | [0.05, 0.89]
 20 |      0.21 | [0.03, 0.70]
 22 |      0.15 | [0.01, 0.70]
 24 |      0.10 | [0.00, 0.74]
 28 |      0.05 | [0.00, 0.86]
 34 |      0.01 | [0.00, 0.96]

Adjusted for:
*  cyl =   6.19
* disp = 230.72
*   hp = 146.69

I would assume that since the standard errors are different in the regression output, I would see the changes in the ggpredict output as well. What am I missing?

1 Answer 1

1

Strange, I cannot reproduce your example. Do you have package sandwich installed? When I run your code, both CI and SE differ:

library(ggeffects)
data(mtcars)
reg <- glm(vs ~ mpg + cyl + disp + hp, mtcars, family="binomial")

ggpredict(reg, "mpg")
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#>   plots.
#> # Predicted probabilities of vs
#> 
#> mpg | Predicted |     95% CI
#> ----------------------------
#>  10 |      0.70 | 0.02, 1.00
#>  12 |      0.61 | 0.03, 0.99
#>  16 |      0.39 | 0.05, 0.89
#>  20 |      0.21 | 0.03, 0.70
#>  22 |      0.15 | 0.01, 0.70
#>  24 |      0.10 | 0.00, 0.74
#>  28 |      0.05 | 0.00, 0.86
#>  34 |      0.01 | 0.00, 0.96
#> 
#> Adjusted for:
#> *  cyl =   6.19
#> * disp = 230.72
#> *   hp = 146.69
#> 
#> Not all rows are shown in the output. Use `print(..., n = Inf)` to show
#>   all rows.
ggpredict(reg, "mpg", vcov_fun = "vcovHC", vcov_type = "HC1")
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#>   plots.
#> # Predicted probabilities of vs
#> 
#> mpg | Predicted |     95% CI
#> ----------------------------
#>  10 |      0.70 | 0.04, 0.99
#>  12 |      0.61 | 0.05, 0.98
#>  16 |      0.39 | 0.07, 0.84
#>  20 |      0.21 | 0.08, 0.48
#>  22 |      0.15 | 0.05, 0.38
#>  24 |      0.10 | 0.02, 0.37
#>  28 |      0.05 | 0.00, 0.45
#>  34 |      0.01 | 0.00, 0.63
#> 
#> Adjusted for:
#> *  cyl =   6.19
#> * disp = 230.72
#> *   hp = 146.69
#> 
#> Not all rows are shown in the output. Use `print(..., n = Inf)` to show
#>   all rows.

ggpredict(reg, "mpg") |> as.data.frame()
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#>   plots.
#>     x  predicted std.error     conf.low conf.high group
#> 1  10 0.70259351  2.494497 1.747344e-02 0.9968235     1
#> 2  12 0.60535681  2.056297 2.653409e-02 0.9885484     1
#> 3  14 0.49899836  1.652617 3.757648e-02 0.9621327     1
#> 4  16 0.39273047  1.315624 4.677843e-02 0.8949872     1
#> 5  18 0.29573482  1.107940 4.568542e-02 0.7864790     1
#> 6  20 0.21424339  1.105050 3.031314e-02 0.7039801     1
#> 7  22 0.15041153  1.308311 1.344489e-02 0.6969606     1
#> 8  24 0.10310235  1.642913 4.571786e-03 0.7420843     1
#> 9  26 0.06945689  2.045381 1.353191e-03 0.8043664     1
#> 10 28 0.04622510  2.482931 3.730739e-04 0.8628956     1
#> 11 30 0.03050906  2.939941 9.893732e-05 0.9091607     1
#> 12 32 0.02002413  3.408591 2.564065e-05 0.9421399     1
#> 13 34 0.01309385  3.884672 6.548620e-06 0.9641321     1
ggpredict(reg, "mpg", vcov_fun = "vcovHC", vcov_type = "HC1") |> as.data.frame()
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#>   plots.
#>     x  predicted std.error     conf.low conf.high group
#> 1  10 0.70259351 2.0829964 0.0383122772 0.9929123     1
#> 2  12 0.60535681 1.7346301 0.0487080617 0.9787027     1
#> 3  14 0.49899836 1.3958193 0.0606674610 0.9388743     1
#> 4  16 0.39273047 1.0756319 0.0728272983 0.8418890     1
#> 5  18 0.29573482 0.7968433 0.0809524471 0.6668767     1
#> 6  20 0.21424339 0.6182533 0.0750705886 0.4780690     1
#> 7  22 0.15041153 0.6315201 0.0488399517 0.3790411     1
#> 8  24 0.10310235 0.8274665 0.0222040963 0.3678585     1
#> 9  26 0.06945689 1.1135020 0.0083468764 0.3982797     1
#> 10 28 0.04622510 1.4367934 0.0028918349 0.4474840     1
#> 11 30 0.03050906 1.7771230 0.0009655520 0.5060871     1
#> 12 32 0.02002413 2.1263255 0.0003164239 0.5687938     1
#> 13 34 0.01309385 2.4806565 0.0001026144 0.6317112     1

Created on 2024-02-22 with reprex v2.1.0

Sign up to request clarification or add additional context in comments.

1 Comment

Weird. I've edited the original post to show my results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.