Simulate the autoregressive model
The autoregressive (AR) model is arguably the most widely used time series model. It shares the very familiar interpretation of a simple linear regression, but here each observation is regressed on the previous observation. The AR model also includes the white noise (WN) and random walk (RW) models examined in earlier chapters as special cases.
The versatile arima.sim() function used in previous chapters can also be used to simulate data from an AR model by setting the model argument equal to list(ar = phi) , in which phi is a slope parameter from the interval (-1, 1). We also need to specify a series length n.
In this exercise, you will use this command to simulate and plot three different AR models with slope parameters equal to 0.5, 0.9, and -0.75, respectively.
Questo esercizio fa parte del corso
Time Series Analysis in R
Istruzioni dell'esercizio
- Use
arima.sim()to simulate 100 observations of an AR model with slope equal to 0.5. To do so, set themodelargument equal tolist(ar = 0.5)and set thenargument equal to100. Save this simulated data tox. - Use a similar call to
arima.sim()to simulate 100 observations of an AR model with slope equal to 0.9. Save this data toy. - Use a third call to
arima.sim()to simulate 100 observations of an AR model with slope equal to -0.75 Save this data toz. - Use
plot.ts()withcbind()to plot your three ts objects (x,y,z).
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Simulate an AR model with 0.5 slope
x <- arima.sim(model = ___, n = ___)
# Simulate an AR model with 0.9 slope
y <-
# Simulate an AR model with -0.75 slope
z <-
# Plot your simulated data
plot.ts(cbind(___, ___, ___))