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

Exercise

Estimate the random walk model

For a given time series y we can fit the random walk model with a drift by first differencing the data, then fitting the white noise (WN) model to the differenced data using the arima() command with the order = c(0, 0, 0)) argument.

The arima() command displays information or output about the fitted model. Under the Coefficients: heading is the estimated drift variable, named the intercept. Its approximate standard error (or s.e.) is provided directly below it. The variance of the WN part of the model is also estimated under the label sigma^2.

Instructions

100 XP
  • The time series random_walk has already been loaded, and is shown in the adjoining figure. Use diff() to generate the first difference of the data. Save this to rw_diff.
  • Use ts.plot() to plot your differenced data
  • Use arima() to fit the WN model for the differenced data. To do so, set the x argument to rw_diff and set the order argument to c(0, 0, 0). Store the model in model_wn.
  • Store the intercept value of model_wn in int_wn. You can obtain this value using model_wn$coef.
  • Use ts.plot() to reproduce your original plot of random_walk.
  • Add the estimated time trend to the adjoining plot with the function abline(). You can use int_wn as the second argument.