Get Started

Box-Cox transformations for time series

Here, you will use a Box-Cox transformation to stabilize the variance of the pre-loaded a10 series, which contains monthly anti-diabetic drug sales in Australia from 1991-2008.

In this exercise, you will need to experiment to see the effect of the lambda (\(\lambda\)) argument on the transformation. Notice that small changes in \(\lambda\) make little difference to the resulting series. You want to find a value of \(\lambda\) that makes the seasonal fluctuations of roughly the same size across the series.

Recall from the video that the recommended range for lambda values is \(-1 ≤ \lambda ≤ 1\).

This is a part of the course

“Forecasting in R”

View Course

Exercise instructions

  • Plot the a10 series and observe the increasing variance as the level of the series increases.
  • Try transforming the series using BoxCox() in the format of the sample code. Experiment with four values of lambda: 0.0, 0.1, 0.2, and 0.3. Can you determine which lambda value approximately stabilizes the variance?
  • Now compare your chosen value of lambda with the one returned by BoxCox.lambda().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot the series
___

# Try four values of lambda in Box-Cox transformations
a10 %>% BoxCox(lambda = ___) %>% autoplot()
___
___
___

# Compare with BoxCox.lambda()
___

This exercise is part of the course

Forecasting in R

IntermediateSkill Level
4.9+
14 reviews

Learn how to make predictions about the future using time series forecasting in R including ARIMA models and exponential smoothing methods.

ARIMA models provide another approach to time series forecasting. Exponential smoothing and ARIMA models are the two most widely-used approaches to time series forecasting, and provide complementary approaches to the problem. While exponential smoothing models are based on a description of the trend and seasonality in the data, ARIMA models aim to describe the autocorrelations in the data.

Exercise 1: Transformations for variance stabilizationExercise 2: Box-Cox transformations for time series
Exercise 3: Non-seasonal differencing for stationarityExercise 4: Seasonal differencing for stationarityExercise 5: ARIMA modelsExercise 6: Automatic ARIMA models for non-seasonal time seriesExercise 7: Forecasting with ARIMA modelsExercise 8: Comparing auto.arima() and ets() on non-seasonal dataExercise 9: Seasonal ARIMA modelsExercise 10: Automatic ARIMA models for seasonal time seriesExercise 11: Exploring auto.arima() optionsExercise 12: Comparing auto.arima() and ets() on seasonal data

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free