I can easily simulate a data set where the regression residuals are iid with 0 mean and constant variance.

`set.seed(123) x = rnorm(100) y = 50 + 25* x + rnorm(100) df = data.frame(y=y, x=x) `

The data assumes that the population regression equation is $$y = beta_0 + beta_1X_1 + epsilon$$

And $epsilon$ is white noise (0 mean, constant variance).

I want to simulate a data set where the residuals are correlated and assume the following population regression equation

$$

begin{aligned}

y_t &= beta_0 + beta_1X_{1,t} + epsilon_t, \

epsilon_t &= rhoepsilon_{t-1} + v_t, \

end{aligned}

$$

and $v_t$ is white noise (0 mean, constant variance).

How would I create this data frame in R?

**Contents**hide

#### Best Answer

Found it.

`set.seed(123) ar.epsilon <- arima.sim(list(order = c(1,0,0), ar = 0.7), n = 200, sd=20) plot(ar.epsilon) x=rnorm(200) y = 50 + 25*x + ar.epsilon df2 = data.frame(x=x, y=y) lm.mod <- lm(y~., data=df2) summary(lm.mod) `

### Similar Posts:

- Solved – Does a white noise process have constant variance by definition
- Solved – MLE for Linear Regression, student-t distributed error
- Solved – Residualizing dependent variable and two step linear regression
- Solved – Relationship between noise term ($epsilon$) and MLE solution for Linear Regression Models
- Solved – Adding Regressors: How Does the Estimated Variance of the Error Terms Change