Forecasting within limits

It is com­mon to want fore­casts to be pos­i­tive, or to require them to be within some spec­i­fied range [a,b]. Both of these sit­u­a­tions are rel­a­tively easy to han­dle using transformations.

Positive forecasts

To impose a pos­i­tiv­ity con­straint, sim­ply work on the log scale. With the fore­cast pack­age in R, this can be han­dled by spec­i­fy­ing the Box-​​Cox para­me­ter \lambda=0. For exam­ple, con­sider the real price of a dozen eggs (1900−1993; in cents):

fit <- ets(eggs, lambda=0)
plot(forecast(fit, h=50))


Forecasts constrained to an interval

To see how to han­dle data con­strained to an inter­val, imag­ine that the egg prices were con­strained to lie within a=50 and b=400. Then we can trans­form the data using a scaled logit trans­form which maps (a,b) to the whole real line:

    \[y = \log\left(\frac{x-a}{b-x}\right)\]

where x is on the orig­i­nal scale and y is the trans­formed data.

# Bounds
a <- 50
b <- 400
# Transform data
y <- log((eggs-a)/(b-eggs))
fit <- ets(y)
fc <- forecast(fit, h=50)
# Back-transform forecasts
fc$mean <- (b-a)*exp(fc$mean)/(1+exp(fc$mean)) + a
fc$lower <- (b-a)*exp(fc$lower)/(1+exp(fc$lower)) + a
fc$upper <- (b-a)*exp(fc$upper)/(1+exp(fc$upper)) + a
fc$x <- eggs
# Plot result on original scale


The pre­dic­tion inter­vals from these trans­for­ma­tions have the same cov­er­age prob­a­bil­ity as on the trans­formed scale, because quan­tiles are pre­served under monot­o­n­i­cally increas­ing trans­for­ma­tions.

Related Posts:

  • hk

    Thanks, this is really useful.