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.
This is a part of the course
“Time Series Analysis in R”
Exercise instructions
- Use
arima.sim()
to generate another RW model. Set themodel
argument equal tolist(order = c(0, 1, 0))
to generate a RW-type model and setn
equal to100
to produce 100 observations. Set themean
argument to1
to produce a drift. Save this torw_drift
. - Use
ts.plot()
to plot yourrw_drift
data. - Use
diff()
to calculate the first difference of yourrw_drift
data. Save this asrw_drift_diff
. - Use another call to
ts.plot()
to plotrw_drift_diff
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Generate a RW model with a drift uing arima.sim
rw_drift <- arima.sim(model = ___, n = ___, mean = ___)
# Plot rw_drift
# Calculate the first difference series
rw_drift_diff <-
# Plot rw_drift_diff