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.
This is a part of the course
“Time Series Analysis in R”
Exercise instructions
- Use
arima.sim()
to generate a 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. Save this torandom_walk
. - Use
ts.plot()
to plot yourrandom_walk
data. - Use
diff()
to calculate the first difference of yourrandom_walk
data. Save this asrandom_walk_diff
. - Use another call to
ts.plot()
to plotrandom_walk_diff
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Generate a RW model using arima.sim
random_walk <- arima.sim(model = ___, n = ___)
# Plot random_walk
# Calculate the first difference series
random_walk_diff <-
# Plot random_walk_diff