Exercise

# Removing seasonal trends with seasonal differencing

For time series exhibiting seasonal trends, seasonal differencing can be applied to remove these periodic patterns. For example, monthly data may exhibit a strong twelve month pattern. In such situations, changes in behavior from year to year may be of more interest than changes from month to month, which may largely follow the overall seasonal pattern.

The function `diff(..., lag = s)`

will calculate the lag `s`

difference or length `s`

seasonal change series. For monthly or quarterly data, an appropriate value of `s`

would be 12 or 4, respectively. The `diff()`

function has `lag = 1`

as its default for first differencing. Similar to before, a seasonally differenced series will have `s`

fewer observations than the original series.

Instructions

**100 XP**

- The time series
`x`

has already been loaded, and is shown in the adjoining figure ranging below -10 to above +10. Apply the`diff(..., lag = 4)`

function to`x`

, saving the result as`dx`

. - Use
`ts.plot()`

to show the transformed series`dx`

and note the condensed vertical range of the transformed data. - Use two calls of
`length()`

to calculate the number of observations in`x`

and`dx`

, respectively.