[R] Problem with coeftest using Newey West estimator

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Mon Dec 14 14:40:40 CET 2009


On Mon, 14 Dec 2009, Bender, Marina wrote:

> I give you a reproducable example from my data:

One of my suspicion's was correct: too few data.

You have 6 observations with which you estimate 4 regression coefficients. 
That's already questionable. But then, to obtain the standard errors, you 
want to prewhite the estimating functions (= fitting a VAR(1) to the 
4-dimensional series of length 6) and finally apply a kernel smoother to 
the prewhitened estimating functions to obtain the 4 standard errors.

In short: This is far too complex for the amount of data you have and 
should not have been employed in the first place.

The explanation for the error message you see is: The problems above lead 
to numerical instabilities which produce a determinant of about -7e-17 
which should be >= 0. This happens in ar.ols() (so not in NeweyWest()). 
I'll send an e-mail to R-devel about this so that a more useful error 
message can be thrown in the future.

Best,
Z

> ## packages
> library("sandwich")
> library("lmtest")
>
> ## data
> DYF <- c(-0.1164, 0.1164, -0.1164, -0.1287, 0.1287, 0.4127)
> BIP <- c(0.063, 0.039, 0.057, 0.036, 0.052, 0.033)
> AQ <- c(-0.3, -0.9, -0.1, 0.2, 0.0, 1.4)
> BrInv_t <- c(0.044, 0.044, 0.080, 0.042, 0.028, 0.042)
> HU_F <- as.data.frame(cbind(DYF, BIP, AQ, BrInv_t))
>
> ## fit + test
> oberlm <- lm(DYF ~ BIP + AQ + BrInv_t, data=HU_F)
> coeftest(oberlm, vcov = NeweyWest(oberlm, lag=2))
>
> ## result of the test I get:
> Fehler in if ((dimension < 1) | (dimension > n)) stop("wrong embedding dimension") :
>  Argument hat Länge 0
> Zusätzlich: Warning message:
> In log(det(varE[[m - order.min + 1]])) : NaNs wurden erzeugt
>
> But when I test the fit on another sample, it works!
>> DYH <- c(-0.2451, 0.1287, 0.0000, -0.1287, -0.1443, 0.3895)
>> BIP <- c(0.063, 0.039, 0.057, 0.036, 0.052, 0.033)
>> Infl <- c(0.0, -0.9, -3.9, -0.5, 2.1, -3.3)
>> EOil <- c(-0.0089, 0.0249, -0.0038, -0.0044, 0.0082, 0.0108)
>> HU_H <- as.data.frame(cbind(DYH, BIP, Infl, EOil))
>> oberlm <- lm(DYH ~ BIP + Infl + EOil, data=HU_H)
>> coeftest(oberlm, vcov = NeweyWest(oberlm, lag=2))
>
> t test of coefficients:
>
>              Estimate Std. Error  t value Pr(>|t|)
> (Intercept)  0.1509950  0.0743832   2.0300 0.179486
> BIP         -5.5131683  1.2536813  -4.3976 0.048016 *
> Infl        -0.0623530  0.0036215 -17.2175 0.003356 **
> EOil         8.6762170  0.0853216 101.6884 9.67e-05 ***
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> -----Ursprüngliche Nachricht-----
> Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Achim Zeileis
> Gesendet: Montag, 14. Dezember 2009 12:42
> An: Bender, Marina
> Cc: r-help at r-project.org
> Betreff: Re: [R] Problem with coeftest using Newey West estimator
>
>
>
> On Mon, 14 Dec 2009, Bender, Marina wrote:
>
>>
>> Hi,
>> As I didn't get a response last week, I try it again.
>>
>> I want to calculate the t- and p-values for a linear model using the Newey West estimator.
>> I tried this Code and it usually worked just fine:
>>
>>> oberlm <- lm(DYH ~ BIP + Infl + EOil, data=HU_H)
>>> coeftest(oberlm, NeweyWest(oberlm, lag=2))
>>
>> t test of coefficients:
>>
>>              Estimate Std. Error  t value Pr(>|t|)
>> (Intercept)  0.1509950  0.0743832   2.0300 0.179486
>> BIP         -5.5131683  1.2536813  -4.3976 0.048016 *
>> Infl        -0.0623530  0.0036215 -17.2175 0.003356 **
>> EOil         8.6762170  0.0853216 101.6884 9.67e-05 ***
>> ---
>> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>>
>>
>>
>> But then I got an error and I don't understand what it means or even why it occurs now:
>>
>>> oberlm <- lm(DYI ~ BIP + BrInv_bw + EOil, data=HU_I)
>>> coeftest(oberlm, NeweyWest(oberlm, lag=2))
>> Fehler in if ((dimension < 1) | (dimension > n)) stop("wrong embedding dimension") :
>>  Argument hat L?nge 0
>> Zus?tzlich: Warning message:
>> In log(det(varE[[m - order.min + 1]])) : NaNs wurden erzeugt
>>
>> Can anyone understand there the problem is?
>
> No, the information above is not enough to replicate the problem. I tried:
>
> ## packages
> library("sandwich")
> library("lmtest")
>
> ## artificial data
> set.seed(123)
> HU_I <- as.data.frame(matrix(rnorm(40), ncol = 4))
> colnames(HU_I) <- c("DYI", "BIP", "BrInv_bw", "EOil")
>
> ## fit + test
> oberlm <- lm(DYI ~ BIP + BrInv_bw + EOil, data=HU_I)
> coeftest(oberlm, NeweyWest(oberlm, lag=2))
>
> So clearly there is something going on on your side that is non-standard
> in some way, e.g., HU_I or one of its columns might be of a non-standard
> class, there might be too few observations or something else. I don't
> know, I haven't seen the error above.
>
> Look at the posting guide which asks you to provide a small reproducible
> example. Trying to find one, often helps you to get closer to the source
> of the problem. traceback() might also help you to get a (partial)
> solution.
>
> Best,
> Z
>
>> Best,
>> Marina
>>
>>
>>
>>
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>>
>
> ______________________________________________
> 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.
>
> ______________________________________________
> 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