BG Test
BG test - To check for autocorrelation in errors
This is LM test to check for the autocorrelation
> x <- rep(c(1, -1), 50)
> y1 <- 1 + x + rnorm(100)
> bgtest(y1 ~ x)
Breusch-Godfrey test for serial correlation of order 1
data: y1 ~ x
LM test = 0.0046, df = 1, p-value = 0.9458 |
Test the fourth order serial correlation
> bgtest(y1 ~ x, order = 4)
Breusch-Godfrey test for serial correlation of order 4
data: y1 ~ x
LM test = 5.7028, df = 4, p-value = 0.2225 |
Compare with Durbin-Watson test results:
> dwtest(y1 ~ x)
Durbin-Watson test
data: y1 ~ x
DW = 2.0117, p-value = 0.5635
alternative hypothesis: true autocorrelation is greater than 0 |
MA residual process check
> y2 <- filter(y1, 0.5, method = "recursive")
> bgtest(y2 ~ x)
Breusch-Godfrey test for serial correlation of order 1
data: y2 ~ x
LM test = 19.2194, df = 1, p-value = 1.165e-05 |