1. Transformations for variance stabilization
With ETS models, we used multiplicative errors and multiplicative seasonality to handle time series that have variance which increases with the level of the series.
2. Variance stabilization
An alternative approach is to transform the time series.
Some common transformations are square roots, cube roots, logarithms, and inverses. You can think of these on a scale of transformations with increasing strength. The further along the scale you go, the greater the effect of the transformation.
Let me illustrate on some data.
3. Variance stabilization
Here we have monthly US net electricity generation. There is an upward trend, and strong seasonality, driven by the use of heating and airconditioning. Clearly the size of the seasonal fluctuations is greater when the level of the series is higher. When we use transformations, we are attempting to make those fluctuations approximately even across the whole series.
4. Variance stabilization
A square root has a relatively small effect in this case.
5. Variance stabilization
Cube root is stronger
6. Variance stabilization
and a logarithm is stronger still. But the fluctuations at the top end are still larger than the fluctuations at the bottom end. So let's try an inverse transformation.
7. Variance stabilization
Now we seem to have gone too far. The seasonal fluctuations at the top end are now smaller than the seasonal fluctuations at the bottom end. So we need something between the log transformation and the inverse transformation if we want to stabilize the variance of this series.
8. Box-Cox transformations
These four transformations are closely related to the family of Box-Cox transformations. It has a single parameter lambda, which controls how strong the transformation is. lambda equals 1 is essentially no transformation - it simply subtracts one from all observations. lambda equals 1/2 is like a square root, lambda equals 1/3 like a cube root, lambda equals 0 equivalent to a log transformation and lambda equals -1 very similar to an inverse transformation. We can use all the lambda values in between these values to get other transformations.
You might try a few values yourself until you have something that looks about right.
9. Box-Cox transformations
Or you could use the BoxCox-dot-lambda function which returns an estimate of lambda that should roughly balance the variation across the series. In this case, it has chosen a value between -1 and 0, as we would expect given the previous graphs we saw.
10. Back-transformation
Once you have chosen lambda, you simply need to add it to the modelling function you are using, and R will take care of the rest.
Here, we have used lambda equals -0-point-57 in the ets function. R will transform the time series using the chosen Box-Cox transformation, and then fit an ETS model. When you pass the resulting model to the forecast function, it passes along the information about the transformation as well. So the forecast function will produce forecasts from the ETS model, and then back-transform them by undoing the Box-Cox transformation, to give forecasts on the original scale. Notice how the seasonal fluctuations in the forecasts are much the same size as those at the end of the data.
It is not very common to use a Box-Cox transformation with an ETS model like this, as ETS models are capable of handling the increasing variance directly by using multiplicative error and seasonal components in the model. But soon we will be using ARIMA models, and then we will need transformations to handle time series with increasing variance.
11. Let's practice!
Let's practice transforming data in the next exercise.