require(tseries)
# if you dont have above package, please install it
# it can be done by running following code
# install.packages('tseries')
########### function that simulates 100 times for hetro-
test_gen=function(n,m){
esp=0
saved=0
for(i in 1:m){ # simulate 100 times
X=rnorm(n,25,1)
for(j in 1:length(X)){
eps[j]=rnorm(1,0,sqrt((X[j])^2)[1])
}
Y=1.5*X+eps
temp=white.test(X,Y)
saved[i]=temp$p.value
}
return(saved)
}
#red dots are the values less than 0.05
#n controls the size of sample
#m controls numbers of simulation
n=20
m=100
out=test_gen(n,m)
plot(c(1:length(out)),out,main="p-value(whitetest) for each simulated data")
ind=out<0.05
points(c(1:length(out))[ind],out[ind],col='red',pch=16)
out2=0
#simulate 100 times for each specific data size
for(i in 20:100){
k=i-19
temp=test_gen(i,100)
out2[k]=sum(temp<0.5)/100
}
plot(20:100,out2,main="error rate",xlab="sample size") # error rate
I feel like I'm doing your homework...anyway good luck