knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Different authors have developed a multiplicity of test for seasonality of a given time series. In Ollech and Webel (forthcoming) and Webel and Ollech (forthcoming) we analysed many of these tests and showed a) which tests are the most reliable ones and b) how to combine a small set of tests, to reduce the misclassification rates of the single tests.
We'll simulated simple non-seasonal and a seasonal series.
set.seed(5) x1 = 1:96/20 + ts(rnorm(96, 100, 1), start=c(2015,1), frequency=12) x2 = 1:96/20 + ts(rnorm(96, 100, 1) + ts(sin((2*pi*rep(1:12, 8))/12), frequency=12), start=c(2015,1), frequency=12) ts.plot(x1,x2, col=c("darkblue", "darkred"), main="Some simple seasonal series") legend("topleft", c("Non seasonal series", "Seasonal series"), col=c("darkblue", "darkred"), lty=1)
Then, we can test, whether these series are seasonal or not, using the WO-test, i.e. the overall seasonality test developed in Webel and Ollech (2019).
library(seastests) print("Testing the non-seasonal series") summary(wo(x1)) print("") print("Testing the seasonal series") summary(wo(x2))
The WO-test gives out a TRUE if the series is seasonal and FALSE otherwise. The p-values indicate the p-values of the underlying test, i.e. the QS-test, the QS-R test and the KW-R-test.
If we are only interested in knowing, whether a series is seasonal or not, e.g. for further use in our analysis, the function isSeasonal() can be called.
print("Test using the non-seasonal series") isSeasonal(x1) print("Test using the seasonal series") isSeasonal(x2)
This can then for example be used in the forecast packages auto.arima() function. For the non-seasonal series:
if (!require("forecast")) install.packages("forecast") mod1 <- auto.arima(x1, seasonal=isSeasonal(x1)) summary(mod1) plot(forecast(mod1, h=12))
and for the seasonal series:
mod2 <- auto.arima(x2, seasonal=isSeasonal(x2)) summary(mod2) plot(forecast(mod2, h=12))
Ollech, Daniel and Webel, Karsten (forthcoming). A random forest-based approach to identifying the most informative seasonality tests. Bundesbank Discussion Paper Webel, Karsten and Ollech, Daniel (forthcoming). An overall seasonality test. Bundesbank Discussion Paper
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.