Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dual seasonal cycles in ts object

I want to strip out seasonality from a ts. This particular ts is daily, and has both yearly and weekly seasonal cycles (frequency 365 and 7).

In order to remove both, I have tried conducting stl() on the ts with frequency set to 365, before extracting trend and remainders, and setting the frequency of the new ts to 7, and repeat.

This doesn't seem to be working very well and I am wondering whether it's my approach, or something inherent to the ts which is causing me problems. Can anyone critique my methodology, and perhaps recommend an alternate approach?

like image 629
Jonathan Mulligan Avatar asked Jan 08 '14 10:01

Jonathan Mulligan


People also ask

What are the types of seasonality?

Hourly data usually has three types of seasonality: a daily pattern, a weekly pattern, and an annual pattern. Even weekly data can be challenging to forecast as it typically has an annual pattern with seasonal period of 365.25/7≈52.179 365.25 / 7 ≈ 52.179 on average.

What is seasonal trend decomposition?

Seasonal-Trend decomposition using LOESS (STL) is a robust method of time series decomposition often used in economic and environmental analyses. The STL method uses locally fitted regression models to decompose a time series into trend, seasonal, and remainder components.

What is the frequency for daily data?

Daily data There could be a weekly cycle or annual cycle. So the frequency could be 7 or 365.25. Some of the years have 366 days (leap years). So if your time series data has longer periods, it is better to use frequency = 365.25.


1 Answers

There is a very easy way to do it using a TBATS model implemented in the forecast package. Here is an example assuming your data are stored as x:

library(forecast)
x2 <- msts(x, seasonal.periods=c(7,365))
fit <- tbats(x2)
x.sa <- seasadj(fit)

Details of the model are described in De Livera, Hyndman and Snyder (JASA, 2011).

like image 134
Rob Hyndman Avatar answered Sep 20 '22 17:09

Rob Hyndman