How to specify interval or frequency with tsibble and fable for service hours?
Asked Answered
Q

1

6

I want to forecast the number of customers entering a shop during service hours. I have hourly data for

  • Monday to Friday
  • 8:00 to 18:00

Thus, I assume my time series is in fact regular, but atypical in a sense, since I have 10 hours a day and 5 days a week.

I am able to do modeling with this regular 24/7 time series by setting non-service hours to zero, but I find this inefficient and also incorrect, because the times are not missing. Rather, they do not exist.

Using the old ts-framework I was able to explicitly specify

myTS <- ts(x, frequency = 10)

However, within the new tsibble/fable-framework this is not possible. It detects hourly data and expects 24 hours per day and not 10. Every subsequent function reminds me of implicit gaps in time. Manually overriding the interval-Attribute works:

> attr(ts, "interval") <- new_interval(hour = 10)
> has_gaps(ts)
# A tibble: 1 x 1
.gaps
<lgl>
1 FALSE

But has no effect on modeling:

model(ts,
      snaive = SNAIVE(customers ~ lag("week")))

I still get the same error message:

1 error encountered for snaive [1] .data contains implicit gaps in time. You should check your data and convert implicit gaps into explicit missing values using tsibble::fill_gaps() if required.

Any help would be appreciated.

Quarterphase answered 9/3, 2020 at 9:24 Comment(0)
T
2

This question actually corresponds to this gh issue. As far as I know, there's no R packages that allow users to construct custom schedule, for example to specify certain intra-days and days. A couple of packages provide some specific calendars (like business dates), but none gives a solution to setting up intra days. Tsibble will gain a calendar argument for custom calendars to respect structural missings, when such a package is made available. But currently no support for that.

As you stated, it's hourly data. Hence the data interval should be 1 hour, not 10 hours. However, ts() frequency is seasonal periods, 10 hours per day, for modelling.

Trespass answered 10/3, 2020 at 4:27 Comment(1)
Thanks for the reference, good discussion there. I see the general problem of adding custom calender.However, for me it would be sufficient if I were just able to use the tidy fable modeling-forecasting-pipeline instead of getting the mentioned error. Is there any workaround that let's fable models ignore the gaps in a tsibble (much like when using ts-objects with frequency = 10)?Quarterphase

© 2022 - 2024 — McMap. All rights reserved.