1
$\begingroup$

How do we set frequency if we have data with frequency that is higher than months in a time series?

If we use months, we can set frequency to 12, but for daily data there is no obvious solution because of leap years. Rob J Hyndman suggests to use a frequency of 7, 365.25 or both for dialy time series (depending on data). Further he writes that we can set frequency to 365.25/7for weekly, 365.25/24 for hourly time series, an so on (see overview).

On the other side, a user on stackoverflow writes that "ts only works with a fixed/constant number of points per year... ts requires regularly spaced points. That is the basis of the class. You can't have different numbers of points in different years and if the series has an annual period of fluctuation it makes no sense to claim it is 7 days. Those are just the facts.". Actually the user wrote more that undermined his rejection of the use of 365.25 for daily, 365.25*24 for hourly data, and so on. Unfortunately, the comments were deleted and I can not reproduce them.

I do not know what position is correct. I guess the use of 365.25 is simply a compromise because there is not better way to model it? Or is there another way how we can set frequency? Are there arguments in favour of one of the position?

Remarks

The discussion on SO started about the R function ts but I understand the position of the SO user as a general critic about using 365.25 days although in fact a year has not that equally spaced frequency.

Rob Hyndman does mention that setting frequency with decimals will not work for some analysis because they await integers. But this is not a problem for frequency per hour, minute or seconds. Additionally, my use case is the virtualization of time series where it is okay to have decimals. I build a R package and need to know what frequency the function should expect for daily, ... times series.

$\endgroup$
1
  • $\begingroup$ Probably this needs migrating to Stack Overflow. $\endgroup$
    – usεr11852
    Dec 16, 2021 at 0:29

1 Answer 1

4
$\begingroup$

ts objects were designed for annual, quarterly and monthly series and only allow for one type of seasonality. If you must use ts objects for daily data, you have to decide which of the seasonalities is most important. Use frequency 7 if you want to model weekly seasonality and frequency 365.25 (or 365 if it must be integer) if you want to model yearly seasonality. A better solution is to use the msts class in the forecast package which allows for multiple seasonal periods. For example, with daily data you would specify the frequencies as follows:

msts(data, seasonal.periods=c(7,365.25))

But that is still rather clumsy. The best way to do it is to use a tsibble object which has an explicit time/date index column. See https://otexts.com/fpp3/tsibbles.html for an introduction.

$\endgroup$
2
  • $\begingroup$ I understand that ts is not designed for daily data, for example. But in my case not I set the frequency but the user will provide some time series, thus, I cannot prevent them to use ts for weekly/daily/ hourly/... data. So the question is what the best representation would be for weekly/daily/ hourly/... data in ts. Here you used ts with frequency of 365.25 for daily data: fourier(ts(x, frequency=365.25), K=5)), for example. $\endgroup$
    – user248711
    Dec 16, 2021 at 7:20
  • $\begingroup$ See edited answer $\endgroup$ Dec 16, 2021 at 23:29

Your Answer

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