[R] sandwich package: HAC estimators

Achim Zeileis Achim.Zeileis at uibk.ac.at
Tue May 31 18:19:04 CEST 2016


On Tue, 31 May 2016, T.Riedle wrote:

> Many thanks for your feedback.
>
> If I get the code for the waldtest right I can calculate the Chi2 and 
> the F statistic using waldtest().

Yes. In a logit model you would usually use the chi-squared statistic.

> Can I use the waldtest() without using bread()/ estfun()? That is, I 
> estimate the logit regression using glm() e.g. logit<-glm(...) and 
> insert logit into the waldtest() function.
>
> Does that work to get chi2 under HAC standard errors?

I'm not sure what you mean here but I include a worked example. Caveat: 
The data I use are cross-section data with an overly simplified set of 
regressors. So none of this makes sense for the application - but it shows 
how to use the commands.

## load AER package which provides the example data
## and automatically loads "lmtest" and "sandwich"
library("AER")
data("PSID1976", package = "AER")

## fit a simple logit model and obtain marginal Wald tests
## for the coefficients and an overall chi-squared statistic
m <- glm(participation ~ education, data = PSID1976, family = binomial)
summary(m)
anova(m, test = "Chisq")

## replicate the same statistics with coeftest() and lrtest()
coeftest(m)
lrtest(m)

## the likelihood ratio test is asymptotically equivalent
## to the Wald test leading to a similar chi-squared test here
waldtest(m)

## obtain HAC-corrected (Newey-West) versions of the Wald tests
coeftest(m, vcov = NeweyWest)
waldtest(m, vcov = NeweyWest)

Instead of NeweyWest other covariance estimators (e.g., vcovHAC, kernHAC, 
etc.) can also be plugged in.

hth,
Z

> ________________________________________
> From: Achim Zeileis <Achim.Zeileis at uibk.ac.at>
> Sent: 31 May 2016 13:18
> To: T.Riedle
> Cc: r-help at r-project.org
> Subject: Re: [R] sandwich package: HAC estimators
>
> On Tue, 31 May 2016, T.Riedle wrote:
>
>> I understood. But how do I get the R2 an Chi2 of my logistic regression
>> under HAC standard errors? I would like to create a table with HAC SE
>> via e.g. stargazer().
>>
>> Do I get these information by using the functions
>>
>> bread.lrm <- function(x, ...) vcov(x) * nobs(x)
>> estfun.lrm <- function(x, ...) residuals(x, "score")?
>>
>> Do I need to use the coeftest() in this case?
>
> The bread()/estfun() methods enable application of vcovHAC(), kernHAC(),
> NeweyWest(). This in turn enables the application of coeftest(),
> waldtest(), or linearHypothesis() with a suitable vcov argument.
>
> All of these give you different kinds of Wald tests with HAC covariances
> including marginal tests of individual coefficients (coeftest) or global
> tests of nested models (waldtest/linearHypothesis). The latter can serve
> as replacement for the "chi-squared test". For pseudo-R-squared values I'm
> not familiar with HAC-adjusted variants.
>
> And I'm not sure whether there is a LaTeX export solution that encompasses
> all of these aspects simultaneously.
>
>> ________________________________________
>> From: R-help <r-help-bounces at r-project.org> on behalf of Achim Zeileis <Achim.Zeileis at uibk.ac.at>
>> Sent: 31 May 2016 08:36
>> To: Leonardo Ferreira Fontenelle
>> Cc: r-help at r-project.org
>> Subject: Re: [R] sandwich package: HAC estimators
>>
>> On Mon, 30 May 2016, Leonardo Ferreira Fontenelle wrote:
>>
>>> Em Sáb 28 mai. 2016, às 15:50, Achim Zeileis escreveu:
>>>> On Sat, 28 May 2016, T.Riedle wrote:
>>>>> I thought it would be useful to incorporate the HAC consistent
>>>>> covariance matrix into the logistic regression directly and generate an
>>>>> output of coefficients and the corresponding standard errors. Is there
>>>>> such a function in R?
>>>>
>>>> Not with HAC standard errors, I think.
>>>
>>> Don't glmrob() and summary.glmrob(), from robustbase, do that?
>>
>> No, they implement a different concept of robustness. See also
>> https://CRAN.R-project.org/view=Robust
>>
>> glmrob() implements GLMs that are "robust" or rather "resistant" to
>> outliers and other observations that do not come from the main model
>> equation. Instead of maximum likelihood (ML) estimation other estimation
>> techniques (along with corresponding covariances/standard errors) are
>> used.
>>
>> In contrast, the OP asked for HAC standard errors. The motivation for
>> these is that the main model equation does hold for all observations but
>> that the observations might be heteroskedastic and/or autocorrelated. In
>> this situation, ML estimation is still consistent (albeit not efficient)
>> but the covariance matrix estimate needs to be adjusted.
>>
>>>
>>> Leonardo Ferreira Fontenelle, MD, MPH
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


More information about the R-help mailing list