[R] Breusch-pagan and white test - check homoscedasticity

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Sat Oct 17 01:31:46 CEST 2009


On Fri, 16 Oct 2009, Gautier RENAULT wrote:

> Hi r-programmers,
>
> I performe Breusch-Pagan tests (bptest in package lmtest) to check the
> homoscedasticity of the residuals from a linear model and I carry out carry
> out White's test via
> bptest (formula, ~ x * z + I(x^2) + I(z^2)) include all regressors and the
> squares/cross-products in the auxiliary regression.
>
> But what can I do if I want find coefficient and p-values of variables x, z,
> x*z, I(x^2), I(z^2) ? **I wish find out which is responsible of
> heteroscedasticity...

To take a reproducible example (cigarette consumption from Baltagi's 
book):

## packages and data
library("AER")
data("CigarettesB")

## regression
cig_lm2 <- lm(packs ~ price + income, data = CigarettesB)

## White test
bptest(cig_lm2, ~ income * price + I(income^2) + I(price^2),
   data = CigarettesB)

The auxiliary regression that is used in this test cannot be extracted 
from bptest() but you can easily run it yourself by hand:

## auxiliary regression
aux <- residuals(cig_lm2)^2 - mean(residuals(cig_lm2)^2)
aux_lm <- lm(aux ~  income * price + I(income^2) + I(price^2),
   data = CigarettesB)

The test statistic is then the n * R-squared:

## test statistic
nrow(CigarettesB) * summary(aux_lm)$r.squared

And then you can also look at the details of the auxiliary model:

summary(aux_lm)

However, this does not have to be very conclusive as in this particular 
example...

hth,
Z

> Can anyone help?
>
> thanking you in advance,
>
> Gautier RENAULT
>
> 	[[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.
>
>




More information about the R-help mailing list