CommencerCommencer gratuitement

Seasonal differencing for stationarity

With seasonal data, differences are often taken between observations in the same season of consecutive years, rather than in consecutive periods. For example, with quarterly data, one would take the difference between Q1 in one year and Q1 in the previous year. This is called seasonal differencing.

Sometimes you need to apply both seasonal differences and lag-1 differences to the same series, thus, calculating the differences in the differences.

In this exercise, you will use differencing and transformations simultaneously to make a time series look stationary. The data set here is h02, which contains 17 years of monthly corticosteroid drug sales in Australia. It has been loaded into your workspace.

Cet exercice fait partie du cours

Forecasting in R

Afficher le cours

Instructions

  • Plot the data to observe the trend and seasonality.
  • Take the log() of the h02 data and then apply seasonal differencing by using an appropriate lag value in diff(). Assign this to difflogh02.
  • Plot the resulting logged and differenced data.
  • Because difflogh02 still looks non-stationary, take another lag-1 difference by applying diff() to itself and save this to ddifflogh02. Plot the resulting series.
  • Plot the ACF of the final ddifflogh02 series using the appropriate function.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Plot the data
___

# Take logs and seasonal differences of h02
difflogh02 <- diff(log(___), lag = ___)

# Plot difflogh02
___

# Take another difference and plot
ddifflogh02 <- ___
___

# Plot ACF of ddifflogh02
___
Modifier et exécuter le code