# White's test for heteroskedasticity in R

I am trying to estimate heteroskedasticity in R. I had Eviews available in my college's lab but not at home. I have been trying to use "het.test" package and whites.htest but the value that I get is different from what I get in Eviews. According to the author of the package, it is meant to do the same test as is done in Eviews.

My model looks like A~B+C. Kindly guide me what I am doing wrong.

I 1st run ols for equation A~B+C, after getting results, I clicked View>Residual diagnostics>Heteroscadicity tests>White's (with Include white cross terms) and then Press ok. The result i got was Prob. F(5,27) = 0.2948.

For R, i tried code at this link [this link][1], here is the edited code that i used.

library(vars)
library(het.test)
dataset <- data.frame(A,B,C))
model1 <- VAR(dataset, p = 1)
whites.htest(model1)


This gave me value of 0.63.

I tried searching this forum but none question seemed related. I am not a programmer not statistician so please pardon my ignorance.

• It is going to be hard to say without more information. Can you paste in the code & output from the 3 tests? Can you say more about your data & your model? Etc. – gung - Reinstate Monica Jun 4 '15 at 12:58
• @gung, please see as i have added details. – Faseeh Jun 4 '15 at 17:52
• Why not lm? Why VAR? – tchakravarty Jun 4 '15 at 17:53
• @T C..Thank you for reply.. i must say, it was there in the code that i quoted, :( can you guide me to the correct usage? – Faseeh Jun 4 '15 at 17:56
• Just write lm(A ~ B + C, data = dataset) where you have VAR right now. – tchakravarty Jun 4 '15 at 17:58

## 1 Answer

The whites.htest() function implements White's test for heteroskedasticity for vector autoregressions (VAR). It requires a varest object as input. However, from your description it seems that your model is not a VAR (vector autoregression) but a simple linear model.

Hence, the model should be estimated by lm() as previously suggested in the comments. Then you can use the bptest() function from the lmtest package to carry out White's test. The latter requires that you set up the terms in the auxiliary model yourself. It should look like this:

m <- lm(A ~ B + C, data = dataset)
bptest(m, ~ B*C + I(B^2) + I(C^2), data = dataset)


Note that B*C includes the main effects and their interaction (= product). Equivalently - and maybe somewhat more explicitly - we could also specify the auxiliary model as ~ A + B + I(A*B) + I(A^2) + I(B^2).

You can also look at

help("CigarettesB", package = "AER")


for a worked example.

• Thank you Sir. I tried it and finally reached correct answer. Thank you so much for help. – Faseeh Jun 5 '15 at 9:43
• @Faseeh, if this has resolved your question, please consider accepting it by clicking the check mark below the vote total on the left. – gung - Reinstate Monica Jun 5 '15 at 9:49
• @gung, thank you for guiding me, i will keep visiting. :) – Faseeh Jun 5 '15 at 9:53