Reputation: 15
I have a question regarding generating errors with heteroscedasticity
This is how my friend told me to do it:
n <- 30
x1 <- rnorm(n,0,1) # 1st predictor
x2 <- rnorm(n,0,1) # 2nd predictor
e <- rnorm(n,0,x1^2) # errors with heteroscedaticity
b1 <- 0.5; b2 <- 0.5
y <- x1*b1+x2*b2+e
For me, e <-rnorm(n,0,x1^2)
-- this is autocorrelation rather than heteroscedastic error distribution.
But my friend said this is the correct way to generate errors with heteroscedasticity.
Am I missing something here?
I thought heteroscedasticity occurs when the variance of the error terms differ across observations.
Does e<-rnorm(n,0,x1^2)
this syntax generate errors with heteroscedasticity correctly?
If not, could anyone tell me how to generate errors with heteroscedasticity?
Upvotes: 0
Views: 276
Reputation: 226532
This specification does generate a particular (slightly odd) kind of heteroscedasticity. You define heteroscedasticity as "the variance of the error term differ[ing] across observations". Since the value of x1
is different for different observations, and you have chosen your error values with a standard deviation of x1^2
, the variances will be different for different observations.
note that
rnorm()
specifies variability in terms of the standard deviation rather than the variancernorm()
chooses independent deviates, so this specification doesn't constitute an autocorrelated sample.Upvotes: 1