MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Time Series Analysis in R

Lihat Kursus

Petunjuk latihan

  • Use arima.sim() to simulate 100 observations of an AR model with slope equal to 0.5. To do so, set the model argument equal to list(ar = 0.5) and set the n argument equal to 100. Save this simulated data to x.
  • Use a similar call to arima.sim() to simulate 100 observations of an AR model with slope equal to 0.9. Save this data to y.
  • Use a third call to arima.sim() to simulate 100 observations of an AR model with slope equal to -0.75 Save this data to z.
  • Use plot.ts() with cbind() to plot your three ts objects (x, y, z).

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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(___, ___, ___))
Edit dan Jalankan Kode