Search code examples
rtime-seriesforecasting

How to plot transformed time series ETS forecast in original units in R?


Is there an easy way to plot transformed time series ETS forecasts (from the forecast package in R) in their original units?

library(forecast)
AP   <- AirPassengers
fit1 <- ets(log(AP), model="AAA")
fit2 <- ets(BoxCox(AP, BoxCox.lambda(AP)), model="AAA")
plot(forecast(fit1)) # Log Transformed
plot(forecast(fit2)) # Box-Cox Transformed

How can I plot the final two lines in the original units of AP? Look at plot(AP)

Likewise, is there an easy way to "back-transform" the confidence intervals from forecast(fit1) and forecast(fit2)?

Note: Not sure if this should exist on CrossValidated instead of SO?


Solution

  • Reading the help files is always a good idea. You will find there that ets has a lambda argument that does what you want.

    library(forecast)
    AP   <- AirPassengers
    fit1 <- ets(AP, model="AAA", lambda=0)
    fit2 <- ets(AP, model="AAA", lambda = BoxCox.lambda(AP))
    plot(forecast(fit1)) 
    plot(forecast(fit2))