Exercise

# Differencing

As seen in the video, when a time series is *trend stationary*, it will have stationary behavior around a trend. A simple example is \(Y_t = \alpha + \beta t + X_t\) where \(X_t\) is stationary.

A different type of model for trend is * random walk*, which has the form \(X_t = X_{t-1} + W_t\), where \(W_t\) is white noise. It is called a random walk because at time \(t\) the process is where it was at time \(t-1\) plus a completely random movement. For a *random walk with drift*, a constant is added to the model and will cause the random walk to drift in the direction (positive or negative) of the drift.

We simulated and plotted data from these models. Note the difference in the behavior of the two models.

In both cases, simple *differencing* can remove the trend and coerce the data to stationarity. Differencing looks at the difference between the value of a time series at a certain point in time and its preceding value. That is, \(X_t - X_{t-1}\) is computed.

To check that it works, you will difference each generated time series and plot the detrended series. If a time series is in `x`

, then `diff(x)`

will have the detrended series obtained by differencing the data. To plot the detrended series, simply use `plot(diff(x))`

.

Instructions

**100 XP**

- In one line, difference and plot the detrended trend stationary data in
`y`

by nesting a call to`diff()`

within a call to`plot()`

. Does the result look stationary? - Do the same for
`x`

. Does the result look stationary?