Exercise

Simulate the random walk model with a drift

A random walk (RW) need not wander about zero, it can have an upward or downward trajectory, i.e., a drift or time trend. This is done by including an intercept in the RW model, which corresponds to the slope of the RW time trend.

For an alternative formulation, you can take the cumulative sum of a constant mean white noise (WN) series, such that the mean corresponds to the slope of the RW time trend.

To simulate data from the RW model with a drift you again use the arima.sim() function with the model = list(order = c(0, 1, 0)) argument. This time, you should add the additional argument mean = ... to specify the drift variable, or the intercept.

Instructions

100 XP
  • Use arima.sim() to generate another 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. Set the mean argument to 1 to produce a drift. Save this to rw_drift.
  • Use ts.plot() to plot your rw_drift data.
  • Use diff() to calculate the first difference of your rw_drift data. Save this as rw_drift_diff.
  • Use another call to ts.plot() to plot rw_drift_diff.