To verify the function AER::bptest
, I manually calculate the test statistic. The manual method and R function give the same result for the Breusch-Pagan test, but not for the White test.
Am I using the bptest
incorrectly, or is my manual calculation wrong?
# A heteroskedastic DGP
x <- rnorm(500)
u <- rnorm(500, sd = sqrt(abs(x)))
y <- 0.01 * x + u
# Manual
m_white <- lm(y ~ x)
uhat <- resid(m_white) ; yhat <- predict(m_white)
m_white_stage2 <- lm(I(uhat^2) ~ yhat + I(yhat^2))
# The test statistic differs!
summary(m_white_stage2)$fstatistic["value"]
bptest(m_white, ~ yhat + I(yhat^2))$statistic