1. Learn
  2. /
  3. Courses
  4. /
  5. Time Series Analysis in R

Exercise

Simulate the random walk model

The random walk (RW) model is also a basic time series model. It is the cumulative sum (or integration) of a mean zero white noise (WN) series, such that the first difference series of a RW is a WN series. Note for reference that the RW model is an ARIMA(0, 1, 0) model, in which the middle entry of 1 indicates that the model's order of integration is 1.

The arima.sim() function can be used to simulate data from the RW by including the model = list(order = c(0, 1, 0)) argument. We also need to specify a series length n. Finally, you can specify a sd for the series (increments), where the default value is 1.

Instructions

100 XP
  • Use arima.sim() to generate a RW model. Set the model argument equal to list(order = c(0, 1, 0)) to generate a RW-type model and set n equal to 100 to produce 100 observations. Save this to random_walk.
  • Use ts.plot() to plot your random_walk data.
  • Use diff() to calculate the first difference of your random_walk data. Save this as random_walk_diff.
  • Use another call to ts.plot() to plot random_walk_diff.