Title: | Seasonality Tests |
---|---|
Description: | An overall test for seasonality of a given time series in addition to a set of individual seasonality tests as described by Ollech and Webel (forthcoming): An overall seasonality test. Bundesbank Discussion Paper. |
Authors: | Daniel Ollech [aut, cre] |
Maintainer: | Daniel Ollech <[email protected]> |
License: | GPL-3 |
Version: | 0.15.4 |
Built: | 2024-10-30 03:14:33 UTC |
Source: | https://github.com/cran/seastests |
Get differenced series
.Diff(x, lag = 1, ...)
.Diff(x, lag = 1, ...)
x |
time series |
lag |
which lag |
... |
further parameters given to diff() Functions used internally in the seasonality package |
Daniel Ollech
Get lag
.Lag(x, k)
.Lag(x, k)
x |
time series |
k |
number of lags Functions used internally in the seasonality package |
Daniel Ollech
Test the residuals of the model used for the OCSB test for serial correlation.
check_residuals(x, plot = F)
check_residuals(x, plot = F)
x |
results of ocsb test |
plot |
boolean, should barplot be printed? |
The residuals of the model used for the OCSB test should ideally be white noise. Here the Ljung-Box statistic is calculated and shown for all lags up to 2 times the frequency of the series. Be aware that the Ljung-Box statistic is a 'cumulative test'. For instance, the p-value of the Ljung-Box statistic for lag 3 is based on the null hypothesis, that the autocorrelations of the first three lags are jointly zero.
Daniel Ollech
Box, G. and G. Jenkins (1970). Time Series Analysis: Forecasting and Control. San Francisco: Holden-Day.
Osborn D.R., Chui A.P.L., Smith J., and Birchenhall C.R. (1988). Seasonality and the order of integration for consumption, Oxford Bulletin of Economics and Statistics 50(4):361-377.
teststat <- ocsb(ts(rnorm(100, 10,10), frequency=12), nrun=100) check_residuals(teststat)
teststat <- ocsb(ts(rnorm(100, 10,10), frequency=12), nrun=100) check_residuals(teststat)
Ollech-Webel overall seasonality test that combines results from different seasonality tests.
combined_test(y, freq = NA)
combined_test(y, freq = NA)
y |
time series |
freq |
Frequency of the time series |
By default, the WO-test combines the results of the QS-test and the kw-test, both calculated on the residuals of an automatic non-seasonal ARIMA model. If the p-value of the QS-test is below 0.01 or the p-value of the kw-test is below 0.002, the WO-test will classify the corresponding time series as seasonal.
If residuals=FALSE the autoarima settings are ignored.
If residuals=TRUE, a non-seasonal ARIMA model is estimated for the time series. And the residuals of the fitted model are used as input to the test statistic. If an automatic order selection is used, the Hyndman-Khandakar algorithm is employed with max(p)=max(q) <= 3.
Daniel Ollech
Ollech, D. and Webel, K. (forthcoming). An overall seasonality test. Deutsche Bundesbank's Discussion Paper series.
Ollech, D. and Webel, K. (2020). A random forest-based approach to identifying the most informative seasonality tests. Deutsche Bundesbank's Discussion Paper series 55/2020.
combined_test(ts(rnorm(120, 10,10), frequency=12)) combined_test(ts(rnorm(120, 10,10), frequency=7))
combined_test(ts(rnorm(120, 10,10), frequency=12)) combined_test(ts(rnorm(120, 10,10), frequency=7))
Estimate the number of periods per year of an xts time series
freq_xts(series)
freq_xts(series)
series |
time series |
The function gives back the average number of observations per year calculated on the whole series except for the first and the last year.
Daniel Ollech
x <- xts::xts(rnorm(100), seq.Date(from=as.Date("2010-01-01"), by="months", length.out=100)) frequency(x)
x <- xts::xts(rnorm(100), seq.Date(from=as.Date("2010-01-01"), by="months", length.out=100)) frequency(x)
Test for seasonality in a time series.
fried(x, freq = NA, diff = T, residuals = F, autoarima = T)
fried(x, freq = NA, diff = T, residuals = F, autoarima = T)
x |
time series |
freq |
Frequency of the time series |
diff |
Shall the differenced series be tested? |
residuals |
Shall the residuals of an ARIMA model be tested? |
autoarima |
Use automatic instead of a (0,1,1) ARIMA model? |
If residuals=FALSE the autoarima settings are ignored.
If residuals=TRUE, a non-seasonal ARIMA model is estimated for the time series. And the residuals of the fitted model are used as input to the test statistic. If an automatic order selection is used, the Hyndman-Khandakar algorithm is employed with max(p)=max(q) <= 3.
Daniel Ollech
Friedman, M. (1937). The Use of Ranks to Avoid the Assumption of Normality Implicit in the Analysis of Variance. Journal of the American Statistical Association 32 (200), 675-701.
Hyndman, R. J. and Y. Khandakar (2008). Automatic Time Series Forecasting: The forecast Package for R. Journal of Statistical Software 27 (3), 1-22.
Ollech, D. and Webel, K. (2020). A random forest-based approach to identifying the most informative seasonality tests. Deutsche Bundesbank's Discussion Paper series 55/2020.
fried(ts(rnorm(120, 10,10), frequency=12)) fried(ts(rnorm(1200, 10,10), frequency=7))
fried(ts(rnorm(120, 10,10), frequency=12)) fried(ts(rnorm(1200, 10,10), frequency=7))
Using a user-chosen seasonality test, the seasonality of a time series is assessed and a boolean value is returned.
isSeasonal(x, test = "combined", freq = NA)
isSeasonal(x, test = "combined", freq = NA)
x |
time series |
test |
Test to be used |
freq |
Frequency of the time series |
By default, the combined-test is used to assess the seasonality of a time series and returns a boolean. Alternatively, the QS test (test='qs'), Friedman test (test='fried'), Kruskall-Wallis (test='kw'), F-test on seasonal dummies (test='seasdum') or the Welch test (test='welch') can be used.
Daniel Ollech
Webel, K. and Ollech, D. (2019). An overall seasonality test. Deutsche Bundesbank's Discussion Paper series.
isSeasonal(ts(rnorm(120, 10,10), frequency=12)) isSeasonal(ts(rnorm(1200, 10,10), frequency=7))
isSeasonal(ts(rnorm(120, 10,10), frequency=12)) isSeasonal(ts(rnorm(1200, 10,10), frequency=7))
Test for seasonality in a time series.
kw(x, freq = NA, diff = T, residuals = F, autoarima = T)
kw(x, freq = NA, diff = T, residuals = F, autoarima = T)
x |
time series |
freq |
Frequency of the time series |
diff |
Shall the differenced series be tested? |
residuals |
Shall the residuals of an ARIMA model be tested? |
autoarima |
Use automatic instead of a (0,1,1) ARIMA model? |
If residuals=FALSE the autoarima settings are ignored.
If residuals=TRUE, a non-seasonal ARIMA model is estimated for the time series. And the residuals of the fitted model are used as input to the test statistic. If an automatic order selection is used, the Hyndman-Khandakar algorithm is employed with max(p)=max(q) <= 3.
Daniel Ollech
Hyndman, R. J. and Y. Khandakar (2008). Automatic Time Series Forecasting: The forecast Package for R. Journal of Statistical Software 27 (3), 1-22.
Kruskal, W. H. and W. A. Wallis (1952). Use of Ranks in One-Criterion Variance Analysis. Journal of the American Statistical Association 47 (260), 583-621.
Ollech, D. and Webel, K. (2020). A random forest-based approach to identifying the most informative seasonality tests. Deutsche Bundesbank's Discussion Paper series 55/2020.
kw(ts(rnorm(120, 10,10), frequency=12)) kw(ts(rnorm(1200, 10,10), frequency=7))
kw(ts(rnorm(120, 10,10), frequency=12)) kw(ts(rnorm(1200, 10,10), frequency=7))
Test for seasonal unit root roots in a time series.
ocsb( x, method = "OLS", augmentations = c(3, 0), freq = NA, nrun = 1000, seed = 123 )
ocsb( x, method = "OLS", augmentations = c(3, 0), freq = NA, nrun = 1000, seed = 123 )
x |
time series |
method |
"OLS" or "ML" |
augmentations |
non-seasonal and seasonal order of the augmentations |
freq |
frequency to be tested |
nrun |
number of runs in monte carlo simulation |
seed |
seed for monte carlo simulated based generation of null distribution |
The null hypothesis of the OCSB is that a series contains a seasonal unit root. This is tested by a Dickey-Fuller type regression. The test regression has often to be augmented by autocorrelational terms to ensure white noise of the error terms.
If seasonal lags are included and method='OLS' the test regression is calculated by OLS, so only the seasonal lags are included. If instead of 'OLS' method='ML' a seasonal AR model is calculated, which implies that high-order non-seasonal lags will be indirectly included as well (see Box and Jenkins, 1970). For seasonal augmentations, ML is quite a bit slower than OLS. The run time can be speeded up by reducing the number of runs of the monte carlo simulation (e.g. nrun=100).
Under the null hypothesis the test statistic follows a non-standard distribution and thus needs to be simulated. The number of runs and the seed can be changed.
Daniel Ollech
Box, G. and G. Jenkins (1970). Time Series Analysis: Forecasting and Control. San Francisco: Holden-Day.
Osborn D.R., Chui A.P.L., Smith J., and Birchenhall C.R. (1988). Seasonality and the order of integration for consumption, Oxford Bulletin of Economics and Statistics 50(4):361-377.
teststat <- ocsb(ts(rnorm(70, 10,10), frequency=7), nrun=200) check_residuals(teststat)
teststat <- ocsb(ts(rnorm(70, 10,10), frequency=7), nrun=200) check_residuals(teststat)
Generic function for class seastests
## S3 method for class 'seastests' print(x, ...)
## S3 method for class 'seastests' print(x, ...)
x |
result from seasonality test |
... |
additional arguments |
Daniel Ollech
a <- qs(ts(rnorm(120, 10,10), frequency=12)) print(a) summary(a)
a <- qs(ts(rnorm(120, 10,10), frequency=12)) print(a) summary(a)
Test for seasonality in a time series.
qs(x, freq = NA, diff = T, residuals = F, autoarima = T)
qs(x, freq = NA, diff = T, residuals = F, autoarima = T)
x |
time series |
freq |
Frequency of the time series |
diff |
Shall the differenced series be tested? |
residuals |
Shall the residuals of ARIMA model be tested? |
autoarima |
Use automatic instead of a (0,1,1) ARIMA model? |
If residuals=FALSE the autoarima settings are ignored.
If residuals=TRUE, a non-seasonal ARIMA model is estimated for the time series. And the residuals of the fitted model are used as input to the test statistic. If an automatic order selection is used, the Hyndman-Khandakar algorithm is employed with max(p)=max(q) <= 3.
Daniel Ollech
Hyndman, R. J. and Y. Khandakar (2008). Automatic Time Series Forecasting: The forecast Package for R. Journal of Statistical Software 27 (3), 1-22.
Maravall, A. (2011). Seasonality Tests and Automatic Model Identification in TRAMO-SEATS. Bank of Spain.
Ollech, D. and Webel, K. (2020). A random forest-based approach to identifying the most informative seasonality tests. Deutsche Bundesbank's Discussion Paper series 55/2020.
qs(ts(rnorm(120, 10,10), frequency=12)) qs(ts(rnorm(1200, 10,10), frequency=7))
qs(ts(rnorm(120, 10,10), frequency=12)) qs(ts(rnorm(1200, 10,10), frequency=7))
Test for seasonality in a time series based on joint significance seasonal dummies in a non-seasonal ARIMA model.
seasdum(x, freq = NA, autoarima = FALSE)
seasdum(x, freq = NA, autoarima = FALSE)
x |
time series |
freq |
Frequency of the time series |
autoarima |
Use automatic instead of a (0,1,1) ARIMA model? |
A RegARIMA model is estimated with (0,1,1)+Seasonal dummies if autoarima=FALSE (default) or (p,d,q)+Seasonal dummies if autoarima=TRUE, (p,d,q) selected by Hyndman-Khandakar algorithm with max(p)=max(q) <= 3. Then the tests checks whether the seasonal dummies are jointly different from zero, i.e. whether deterministic seasonality can be detected in the time series.
Daniel Ollech
Hyndman, R. J. and Y. Khandakar (2008). Automatic Time Series Forecasting: The forecast Package for R. Journal of Statistical Software 27 (3), 1-22.
Maravall, A. (2011). Seasonality Tests and Automatic Model Identification in TRAMO-SEATS. Bank of Spain.
Ollech, D. and Webel, K. (2020). A random forest-based approach to identifying the most informative seasonality tests. Deutsche Bundesbank's Discussion Paper series 55/2020.
seasdum(ts(rnorm(120, 10,10), frequency=12)) seasdum(ts(rnorm(70, 10,10), frequency=7))
seasdum(ts(rnorm(120, 10,10), frequency=12)) seasdum(ts(rnorm(70, 10,10), frequency=7))
Generic functions for class seasinttests
## S3 method for class 'seasinttests' summary(object, ...)
## S3 method for class 'seasinttests' summary(object, ...)
object |
result from seasonal integration test |
... |
additional arguments |
Daniel Ollech
a <- qs(ts(rnorm(120, 10,10), frequency=12)) print(a) summary(a)
a <- qs(ts(rnorm(120, 10,10), frequency=12)) print(a) summary(a)
Generic function for class seastests
## S3 method for class 'seastests' summary(object, ...)
## S3 method for class 'seastests' summary(object, ...)
object |
result from seasonality test |
... |
additional arguments |
Daniel Ollech
a <- qs(ts(rnorm(120, 10,10), frequency=12)) print(a) summary(a)
a <- qs(ts(rnorm(120, 10,10), frequency=12)) print(a) summary(a)
Test for seasonality in a time series using Welch's ANOVA test.
welch(x, freq = NA, diff = T, residuals = F, autoarima = T, rank = F)
welch(x, freq = NA, diff = T, residuals = F, autoarima = T, rank = F)
x |
time series |
freq |
Frequency of the time series |
diff |
Shall the differenced series be tested? |
residuals |
Shall the residuals of an ARIMA model be tested? |
autoarima |
Use automatic instead of a (0,1,1) ARIMA model? |
rank |
Use rank of series instead of actual values? |
If residuals=FALSE the autoarima parameter is ignored.
If rank=TRUE, the test becomes basically a combination of the Kruskall-Wallis and the Welch test.
If residuals=TRUE, a non-seasonal ARIMA model is estimated for the time series. And the residuals of the fitted model are used as input to the test statistic. If an automatic order selection is used, the Hyndman-Khandakar algorithm is employed with max(p)=max(q) <= 3.
Daniel Ollech
Kruskal, W. H. and W. A.Wallis (1952). Use of Ranks in One-Criterion Variance Analysis. Journal of the American Statistical Association 47 (260), 583-621.
Welch, B. L. (1951). On the Comparison of Several Mean Values: An Alternative Approach. Biometrika 38 (3/4), 330-336.
welch(ts(rnorm(120, 10,10), frequency=12)) welch(ts(rnorm(1200, 10,10), frequency=7))
welch(ts(rnorm(120, 10,10), frequency=12)) welch(ts(rnorm(1200, 10,10), frequency=7))