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.
Este ejercicio forma parte del curso
Time Series Analysis in R
Instrucciones del ejercicio
- Use
arima.sim()
to simulate 100 observations of an AR model with slope equal to 0.5. To do so, set themodel
argument equal tolist(ar = 0.5)
and set then
argument 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
).
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# 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(___, ___, ___))