Get startedGet started for free

Confidence Intervals for Forecast

Your forecast object forecast_MET_t not only has the forecast, but also margin of error calculations for the forecast called confidence intervals. These confidence intervals show us a wiggle room on our forecasts since no forecast is ever perfect.

The forecast was stored as the object forecast_MET_t$mean. The upper and lower limit of this interval is stored similarly. The second column of the upper confidence interval is the 95% confidence interval and can be accessed via forecast_MET_t$upper[,2]. To get the lower limit replace the word upper with lower.

This exercise is part of the course

Forecasting Product Demand in R

View Course

Exercise instructions

  • Convert both the upper and lower 95% confidence limits to xts objects upper and lower. Your date index is stored as for_dates.
  • Add these to the plot of the forecast and the validation data set.

Hands-on interactive exercise

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

# Plot the validation data set
plot(MET_t_valid, main = 'Forecast Comparison', ylim = c(4000, 8500))

# Overlay the forecast of 2017
lines(for_MET_t_xts, col = "blue")

# Convert the limits to xts objects
lower <- xts(forecast_MET_t$___[,2], order.by = ___)
upper <- xts(___$___[,___], order.by = for_dates)

# Adding confidence intervals of forecast to plot
lines(lower, col = "blue", lty = "dashed")
lines(___, col = "blue", lty = "dashed")
Edit and Run Code