# R-square and p-value for regression with robust standard errors

Hello,

I would like to calculate the R-Squared and p-value (F-Statistics) for my model (with Standard Robust Errors). Can someone explain to me how to get them for the adapted model (modrob)?

The regression without standard robust error:

``````>mod=lm(giniA~region+dummy_2009+age,data=fors)

Call:
lm(formula = giniA ~ region + dummy_2009 + age, data = fors)

Residuals:
Min       1Q   Median       3Q      Max
-0.13714 -0.01402  0.00192  0.01458  0.09922

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  6.167e-01  1.917e-03 321.749  < 2e-16 ***
regionWest   2.218e-03  1.408e-03   1.575    0.115
dummy_2009  -2.225e-02  1.205e-03 -18.473  < 2e-16 ***
age         -1.858e-04  3.858e-05  -4.816  1.6e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.02381 on 1624 degrees of freedom
Multiple R-squared:  0.2034,	Adjusted R-squared:  0.202
F-statistic: 138.3 on 3 and 1624 DF,  p-value: < 2.2e-16

``````

And this is my regression with standard robust errors, for which I would like to calculate the R-squared and p-value(F-statistics):

``````# model with robust standard errors:

> modrob = coeftest(mod,vcov. = vcovHAC)

t test of coefficients:

Estimate  Std. Error  t value  Pr(>|t|)
(Intercept)  6.1666e-01  2.0404e-03 302.2289 < 2.2e-16 ***
regionWest   2.2179e-03  1.4474e-03   1.5324    0.1256
dummy_2009  -2.2254e-02  1.1846e-03 -18.7869 < 2.2e-16 ***
age         -1.8582e-04  4.2784e-05  -4.3431 1.491e-05 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
``````

Thank you very much.

Hi,

Could you provide us with a minimal reproducible example (dummy data + script) so we can run the code ourselves and see where the issue lies.

Thanks,
PJ

For robust regression in general you might try looking here: https://declaredesign.org/r/estimatr/reference/lm_robust.html

Dear Sir,

Enclosed are the script and the data.
fors.pdf (27.5 KB)

Unfortunately the system doesn't allow me to upload my data, only as pdf. I hope it works that way for you.

The codes are the following:

``````mod=lm(giniA~ region+as.factor(year)+factor(sex)+age,data=fors)
summary(mod)

#Test
library(lmtest)
bptest(mod)

#robust standard errors
library(sandwich)
coeftest(mod,vcov. = vcovHAC)

``````

Thank you very much for your help.

Perfect! Thank you very much for the hint, pete.

Hi,

I am not a statistician, but I believe the R squared is not changed by the fact you use robust regression. After looking it up, they say indeed it's the same and it's not shown because you don't trust this statistic when you do the robust regression (that's the point you're doing it).

See this post:

FYI, if you like to extract the R squared from the original model, you can:

``````summary(mod)\$r.squared
summary(mod)\$fstatistic
``````

Hope this helps!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.