library(lmtest)
library(MASS)
library(car)
library(caret)
x = rep(1:100)
a = 10
b = 2
sigma2_2 = x*10
eps = rnorm(x, mean=0, sd=sqrt(sigma2_2))
y2 = a+b*x + eps
model2 = lm(y2 ~ x)
sigma2_3 = x^2*10
eps = rnorm(x,mean=0,sd=sqrt(sigma2_3))
y3 = a+b*x + eps
model3 = lm(y3 ~ x)
par(mfcol=c(1,2))
plot(x,y2,main="mild heteroscedasticity")
abline(coef(model2), col="red")
plot(x,y3,main="severe heteroscedasticity")
abline(coef(model3), col="red")
par(mfcol=c(1,1))
bptest(model2)
bptest(model3)
model2_new <- lm(y2~x, weights = 1/sqrt(x*10))
summary(model2_new)
plot(model2_new)
bptest(model2_new)
model3_new <- lm(y3~x, weights = 1/x)
summary(model3_new)
plot(model3_new)
bptest(model3_new)
y2BCMod <- BoxCoxTrans(y2)
print(y2BCMod)
y2_new=predict(y2BCMod, y2)
Mod2_bc <- lm(y2_new ~ x)
bptest(Mod2_bc)
y3BCMod <- BoxCoxTrans(y3+450)
print(y3BCMod)
y3_new=predict(y3BCMod, y3)
Mod3_bc <- lm(y3_new ~ x)
bptest(Mod3_bc)
I want to compare the box-cox transformation and WLS method in solving the heteroskedasticity problem, but no matter how I simulate the data, it seems the bptest
always rejected the null hypothsis. I am confused. Is there a problem in choosing the weights or other problem in my code?
bptest
rejects the null of homoskedasticity, as it should. What is wrong? Please extend your post by including plots and some output from your code, and explain where you are surprised. $\endgroup$