[R] Heteroskedasticity and Autocorrelation in SemiPar package

Achim Zeileis Achim.Zeileis at wu.ac.at
Sun Jun 28 15:26:22 CEST 2009


On Fri, 26 Jun 2009, Liviu Andronic wrote:

> On Fri, Jun 26, 2009 at 10:11 PM, Susan Chen<suenb16 at yahoo.com> wrote:
>> Does anyone know how to report heteroskedasticity and autocorrelation-consistent standard errors when using the "spm" command in SemiPar package? Suppose the original command is
>> sp1<-spm(y~x1+x2+f(x3), random=~1,group=id)
>>
> There's HAC() in library(gmm), which is a modification from the
> sandwich::vcovHAC(), designed to accept as input any vectors (and not
> only specific objects, such as lm).

That is very wrong in several ways:
   1. It is the other way round: vcovHAC() can accept *any* input (as long
      as there are suitable methods). HAC() on the other hand can *only*
      accept matrices (or matrix-based time series).
   2. If one wants vcovHAC(obj) to work, estfun(obj) must return the
      empirical estimating function (aka score functions) and bread(obj)
      must return an estimate of the "bread" of the sandwich. The former
      can usually be easily extracted from model fits, the latter can
      usually be easily computed from vcov(obj).
   3. If one wants to compute HAC covariances for the variation about the
      overall mean one can easily do vcovHAC(lm(x ~ 1)).
   4. If one wants vcovHAC(x) to work directly, the correct approach would
      be to supply suitable methods (as outlined above) rather than copying
      and modifying the code which is really bad practice.

The details of the object-oriented nature of the package are explained in 
detail in
   vignette("sandwich-OOP", package = "sandwich")

> The sandwich::vcovHAC() can also be relatively easily extended to
> accept other fits as input (not only lm or glm, for example), but this
> would require some understanding of the internals of both SemiPar and
> sandwich. You might enquire if the author of SemiPar is interested in
> adding such functionality. For technical details, check the first
> vignette of sandwich.

I'm not sure how the asymptotic theory for the semi-parametric models 
implemented in spm() works. I would guess that one could implement it so 
that estfun() and bread(), by default, only give the corresponding return 
values for the parametric part of the model. But one would need to check 
whether this is appropriate.

Best,
Z

> Once you get HAC covariance matrix for your fit, you can use either
> lmtest::coeftest or library(car) to obtain the HAC std errs.
> Liviu
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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