Carlos Pita
2012-Sep-18 18:21 UTC
[R] Contradictory results between different heteroskedasticity tests
Hi all, I'm getting contradictory results from bptest and ncvTest on a model calculated by GLS as: olslm = lm(log(rr)~log(aloi)*reg*inv, data) varlm = lm(I(residuals(olslm)^2)~log(aloi)*reg*inv, data) glslm = lm(log(rr)~log(aloi)*reg*inv, data, weights=1/fitted(varlm)) Testing both olslm and glslm with both ncvTest and bptest gives:> ncvTest(olslm)Non-constant Variance Score Test Variance formula: ~ fitted.values Chisquare = 46.88206 Df = 1 p = 7.538963e-12> ncvTest(glslm)Non-constant Variance Score Test Variance formula: ~ fitted.values Chisquare = 0.001466426 Df = 1 p = 0.9694533> bptest(olslm)studentized Breusch-Pagan test data: olslm BP = 213.1477, df = 7, p-value < 2.2e-16> bptest(glslm)studentized Breusch-Pagan test data: glslm BP = 213.1477, df = 7, p-value < 2.2e-16 Please notice the last output. It seems as if bptest is not considering the weights given to lm. What am I doing wrong here? Best regards -- Carlos
John Fox
2012-Sep-18 20:31 UTC
[R] Contradictory results between different heteroskedasticity tests
Dear Carlos, Please note that the default alternative hypothesis is different in ncvTest() and bptest() -- in the former that the error variance is a function of the expectation of Y (hence the formula ~ fitted.values, with 1 df for the test), and in the latter that the error variance is a function of a linear combination of the predictors in the model (hence, in your case, 7 df for the test). For testing a different alternative hypothesis with ncvTest(), see ?ncvTest. I won't comment of what bptest() does with the weighted model, but ncvTest() uses the Pearson residuals and hence takes account of the weights. I hope this helps, John ----------------------------------------------- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Carlos Pita > Sent: Tuesday, September 18, 2012 2:22 PM > To: r-help at r-project.org > Subject: [R] Contradictory results between different heteroskedasticity > tests > > Hi all, > > I'm getting contradictory results from bptest and ncvTest on a model > calculated by GLS as: > > olslm = lm(log(rr)~log(aloi)*reg*inv, data) > varlm = lm(I(residuals(olslm)^2)~log(aloi)*reg*inv, data) > glslm = lm(log(rr)~log(aloi)*reg*inv, data, weights=1/fitted(varlm)) > > Testing both olslm and glslm with both ncvTest and bptest gives: > > > ncvTest(olslm) > Non-constant Variance Score Test > Variance formula: ~ fitted.values > Chisquare = 46.88206 Df = 1 p = 7.538963e-12 > > > ncvTest(glslm) > Non-constant Variance Score Test > Variance formula: ~ fitted.values > Chisquare = 0.001466426 Df = 1 p = 0.9694533 > > > bptest(olslm) > studentized Breusch-Pagan test > data: olslm > BP = 213.1477, df = 7, p-value < 2.2e-16 > > > bptest(glslm) > studentized Breusch-Pagan test > data: glslm > BP = 213.1477, df = 7, p-value < 2.2e-16 > > Please notice the last output. It seems as if bptest is not > considering the weights given to lm. What am I doing wrong here? > > Best regards > -- > Carlos > > ______________________________________________ > 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.