Following the steps of Breusch–Godfrey test , I wrote my own R code which differs from the R function for bgtest under package 'lmtest' . Though both of them reject the null hypothesis that at least one $\rho$ is statistically significant .

I have $30$ observations in my data set and I set the null hypothesis that : $$\rho_1=\rho_2=\rho_3=\rho_4=\rho_5=0$$

 data <- read.csv("exc12.26.csv",header=TRUE)

 lC <- log(C); lI <- log(I); lL <- log(L); lH <- log(H); lA <- log(A)

 lm.y <- lm(lC~lI+lL+lH+lA)
 uhat <- resid(lm.y)

 ##BG test :
 ut_1 <-uhat[5:29];ut_2 <-uhat[4:28];ut_3 <-uhat[3:27];ut_4 <-uhat[2:26];ut_5 <-uhat[1:25]

lm.u <- lm(uhat[6:30]~lI[6:30]+lL[6:30]+lH[6:30]+lA[6:30]+ut_1+ut_2+ut_3+ut_4+ut_5)

R2 <- 0.4943 
chi_cal <- 25*R2

p_val <- pchisq(chi_cal,5,lower.tail=FALSE)
[1] 0.03020434

But if I use the function bgtest , the p-value does not match with my R-code p-value .


 ##Output : p-value = 0.01396


Where am i doing mistake ?

  • $\begingroup$ Do the test statistics match while the p-values do not match? Or do the test statistics not match either? You can always check the code behind an R function by typing the function name and clicking "Enter". That way you could see whether the bgtest code does something different from what your code does. $\endgroup$ – Richard Hardy Jun 6 '15 at 15:03
  • $\begingroup$ @RichardHardy No , statistics also do not match . $\endgroup$ – time Jun 6 '15 at 15:22
  • $\begingroup$ That means you have defined the statistic differently than in bgtest. You could either look for mistakes in your code or -- if you do not trust bgtest -- take a look at the source code of bgtest. $\endgroup$ – Richard Hardy Jun 6 '15 at 15:32

Your implementation of the test statistic omits the lagged residuals for the first five observations, i.e., sets the starting values to NA. However, the implementation in the bgtest() function by default sets the starting values to 0. You can change the default, though, by setting fill = NA.

I hope this resolves the discrepancy. I couldn't check for your data without a reproducible example.

| cite | improve this answer | |
  • $\begingroup$ I wrote bgtest(lm.y,order=5,type="Chisq",fill=NA) but it shows error massage unused argument in bgtest() $\endgroup$ – time Jun 8 '15 at 1:30
  • 1
    $\begingroup$ The feature was added in lmtest 0.9-31 (and the current version is 0.9-34). Probably you have installed an older version. $\endgroup$ – Achim Zeileis Jun 8 '15 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.