Title: | Seasonality Tests |
Version: | 0.15.4 |
Maintainer: | Daniel Ollech <daniel.ollech@bundesbank.de> |
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. |
License: | GPL-3 |
Depends: | R (≥ 3.1.0) |
Encoding: | UTF-8 |
LazyData: | false |
RoxygenNote: | 7.1.1 |
Imports: | xts, zoo, forecast, stats, graphics, utils |
NeedsCompilation: | no |
Packaged: | 2021-09-18 12:24:04 UTC; s3504do |
Author: | Daniel Ollech [aut, cre] |
Repository: | CRAN |
Date/Publication: | 2021-09-18 12:50:02 UTC |
Internal functions
Description
Get differenced series
Usage
.Diff(x, lag = 1, ...)
Arguments
x |
time series |
lag |
which lag |
... |
further parameters given to diff() Functions used internally in the seasonality package |
Author(s)
Daniel Ollech
Internal functions
Description
Get lag
Usage
.Lag(x, k)
Arguments
x |
time series |
k |
number of lags Functions used internally in the seasonality package |
Author(s)
Daniel Ollech
Check model used in OCSB test
Description
Test the residuals of the model used for the OCSB test for serial correlation.
Usage
check_residuals(x, plot = F)
Arguments
x |
results of ocsb test |
plot |
boolean, should barplot be printed? |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
teststat <- ocsb(ts(rnorm(100, 10,10), frequency=12), nrun=100)
check_residuals(teststat)
Ollech and Webel's combined seasonality test
Description
Ollech-Webel overall seasonality test that combines results from different seasonality tests.
Usage
combined_test(y, freq = NA)
Arguments
y |
time series |
freq |
Frequency of the time series |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
combined_test(ts(rnorm(120, 10,10), frequency=12))
combined_test(ts(rnorm(120, 10,10), frequency=7))
Obtain the frequency of an xts time series
Description
Estimate the number of periods per year of an xts time series
Usage
freq_xts(series)
Arguments
series |
time series |
Details
The function gives back the average number of observations per year calculated on the whole series except for the first and the last year.
Author(s)
Daniel Ollech
Examples
x <- xts::xts(rnorm(100), seq.Date(from=as.Date("2010-01-01"), by="months", length.out=100))
frequency(x)
Friedman Rank test
Description
Test for seasonality in a time series.
Usage
fried(x, freq = NA, diff = T, residuals = F, autoarima = T)
Arguments
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? |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
fried(ts(rnorm(120, 10,10), frequency=12))
fried(ts(rnorm(1200, 10,10), frequency=7))
Testing the seasonality of series
Description
Using a user-chosen seasonality test, the seasonality of a time series is assessed and a boolean value is returned.
Usage
isSeasonal(x, test = "combined", freq = NA)
Arguments
x |
time series |
test |
Test to be used |
freq |
Frequency of the time series |
Details
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.
Author(s)
Daniel Ollech
References
Webel, K. and Ollech, D. (2019). An overall seasonality test. Deutsche Bundesbank's Discussion Paper series.
Examples
isSeasonal(ts(rnorm(120, 10,10), frequency=12))
isSeasonal(ts(rnorm(1200, 10,10), frequency=7))
Kruskall Wallis test
Description
Test for seasonality in a time series.
Usage
kw(x, freq = NA, diff = T, residuals = F, autoarima = T)
Arguments
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? |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
kw(ts(rnorm(120, 10,10), frequency=12))
kw(ts(rnorm(1200, 10,10), frequency=7))
OCSB test
Description
Test for seasonal unit root roots in a time series.
Usage
ocsb(
x,
method = "OLS",
augmentations = c(3, 0),
freq = NA,
nrun = 1000,
seed = 123
)
Arguments
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 |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
teststat <- ocsb(ts(rnorm(70, 10,10), frequency=7), nrun=200)
check_residuals(teststat)
Generic function for class seastests
Description
Generic function for class seastests
Usage
## S3 method for class 'seastests'
print(x, ...)
Arguments
x |
result from seasonality test |
... |
additional arguments |
Author(s)
Daniel Ollech
Examples
a <- qs(ts(rnorm(120, 10,10), frequency=12))
print(a)
summary(a)
QS test
Description
Test for seasonality in a time series.
Usage
qs(x, freq = NA, diff = T, residuals = F, autoarima = T)
Arguments
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? |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
qs(ts(rnorm(120, 10,10), frequency=12))
qs(ts(rnorm(1200, 10,10), frequency=7))
F-Test on seasonal dummies
Description
Test for seasonality in a time series based on joint significance seasonal dummies in a non-seasonal ARIMA model.
Usage
seasdum(x, freq = NA, autoarima = FALSE)
Arguments
x |
time series |
freq |
Frequency of the time series |
autoarima |
Use automatic instead of a (0,1,1) ARIMA model? |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
seasdum(ts(rnorm(120, 10,10), frequency=12))
seasdum(ts(rnorm(70, 10,10), frequency=7))
Generic functions for class seasinttests
Description
Generic functions for class seasinttests
Usage
## S3 method for class 'seasinttests'
summary(object, ...)
Arguments
object |
result from seasonal integration test |
... |
additional arguments |
Author(s)
Daniel Ollech
Examples
a <- qs(ts(rnorm(120, 10,10), frequency=12))
print(a)
summary(a)
Generic function for class seastests
Description
Generic function for class seastests
Usage
## S3 method for class 'seastests'
summary(object, ...)
Arguments
object |
result from seasonality test |
... |
additional arguments |
Author(s)
Daniel Ollech
Examples
a <- qs(ts(rnorm(120, 10,10), frequency=12))
print(a)
summary(a)
Welch seasonality test
Description
Test for seasonality in a time series using Welch's ANOVA test.
Usage
welch(x, freq = NA, diff = T, residuals = F, autoarima = T, rank = F)
Arguments
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? |
Details
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.
Author(s)
Daniel Ollech
References
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.
Examples
welch(ts(rnorm(120, 10,10), frequency=12))
welch(ts(rnorm(1200, 10,10), frequency=7))