Exercise

Removing trends in level by differencing

The first difference transformation of a time series \(z[t]\) consists of the differences (changes) between successive observations over time, that is \(z[t] - z[t-1]\).

Differencing a time series can remove a time trend. The function diff() will calculate the first difference or change series. A difference series lets you examine the increments or changes in a given time series. It always has one fewer observations than the original series.

The time series z has already been loaded, and is shown in the figure on the right.

Instructions

100xp

Apply the diff() function to z, saving the result as dz.

Use ts.plot() to view a time series plot of the transformed series dz.

Use two calls of length() to calculate the number of observations in z and dz, respectively.