John
John

Reputation: 1947

How to convert sandwich adjusted p values summary to data frame?

Let's consider following model and it's HAC version of adjusted pvalues :

library(lmtest)
library(sandwich)
set.seed(42)
y <- rnorm(100)
x <- data.frame(runif(100))
model <- lm(y~., data = x)
coeftest(model, vcov = vcovHAC)

t test of coefficients:

            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.09510    0.16125 -0.5898   0.5567
runif.100.   0.28952    0.30452  0.9508   0.3441

I wonder - how can I convert this to data frame ? In standard lm summary we just use command as.data.frame(coef(summary)) but here it seems to not work. How can I do it ?

Upvotes: 0

Views: 194

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389235

broom::tidy can help here.

data <- coeftest(model, vcov = vcovHAC)
broom::tidy(data)

#  term        estimate std.error statistic p.value
#  <chr>          <dbl>     <dbl>     <dbl>   <dbl>
#1 (Intercept)  -0.0951     0.161    -0.590   0.557
#2 runif.100.    0.290      0.305     0.951   0.344

Upvotes: 1

Related Questions