Get Started

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”

View Course

Exercise instructions

  • 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.

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

  
Edit and Run Code