2
$\begingroup$

I have following sample dataset in R

 time                        calls          date
 01-01-2018 08:00-08:59      53             01-01-2018    
 01-01-2018 09:00-09:59      43             01-01-2018
 01-01-2018 10:00-10:59      27             01-01-2018
 01-01-2018 11:00-11:59      50             01-01-2018
 01-01-2018 12:00-12:59      53             01-01-2018
 01-01-2018 13:00-13:59      40             01-01-2018
 01-01-2018 14:00-14:59      33             01-01-2018
 01-01-2018 15:00-15:59      43             01-01-2018
 01-01-2018 16:00-17:00      27             01-01-2018

First column is the call volume at every hour (9 hours shift), I want to forecast at hourly level and daily level(aggregated at day level). I do not want to fit two different time series models for hourly and daily level call forecasting. Is there any model which gives me both level forecasting in same model? I have heard of hierarchical time series models or grouped time series models,but not sure if we can apply them in above scenario

$\endgroup$

1 Answer 1

8
$\begingroup$

Yes, use a temporal hierarchical approach, as implemented in the thief package. It will fit models for hourly, daily and higher levels of temporal aggregation, and then reconcile the forecasts to ensure they are coherent.

For hourly data, you probably want to use something like TBATS as the base model.

First you will need to convert your data to an msts object.

library(thief)
y <- msts(data[['calls']], seasonal.periods=c(9,9*7,9*365))

The seasonal periods are for a 9-hour day, a week, and a year.

Then compute the forecasts as follows.

ftbats <- function(y,h,...){forecast(tbats(y),h,...)}
z <- thief(y, forecastfunction=ftbats)

To get the forecasts at higher levels of temporal aggregation (e.g., daily), use

tsaggregates(z)

The last step will be to add back in the time stamp and dates to the forecasts.

$\endgroup$
4
  • $\begingroup$ Thank you so much Prof. Hyndman. I have one question,if i want to forecast it for next 9 hours(1 day ahead) where do I specify that? Assuming it will give me a forecast at day level as well as hourly level. Do I have to aggregate it manually to day level or it will automatically does that? $\endgroup$
    – Neil
    Commented Jun 20, 2018 at 8:55
  • $\begingroup$ If you just run the code I provided, you will see that tsaggregates does what you ask. See the help file for thief to see how to change the horizon. $\endgroup$ Commented Jun 20, 2018 at 14:18
  • $\begingroup$ @RobHyndman what is the max period for which i can forecast using tbats() with good accuracy? can it be done for more than 48 hours? $\endgroup$ Commented Dec 3, 2019 at 6:20
  • $\begingroup$ I think you mean maximum forecast horizon. That depends on the signal to noise ratio in your data. With strong signal and little noise, you can forecast a very long way ahead. $\endgroup$ Commented Dec 3, 2019 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.