Skip to content

Seasonality tests

Jean Palate edited this page Dec 5, 2015 · 2 revisions

Seasonality tests

JD+ contains several seasonality tests. Most of them are implemented in the package ec.satoolkit.diagnostics. We shortly describe below the most important of them and we provide code explaining the way they should be used.

Non parametric tests

Friedman test

The Friedman test is a non-parametric method that will be used to test the significance of the month (or quarter) effect. The test uses the rankings of the observations and does not require distributional assumptions. If the null hypothesis of no stable seasonality is rejected at the 1% significance level then the series is considered to be seasonal. The test should be applied on the series after differencing, if need be (in practice, sa will be differenced and irregular not)

The test is implemented in the class FriedmanTest

Kruskal-Wallis test

The Kruskal-Wallis test is a non-parametric test used for testing whether samples originate from the same distribution. The parametric equivalent of the Kruskal-Wallis test is the one-way analysis of variance (ANOVA). When rejecting the null hypothesis of the Kruskal-Wallis test, then at least one sample stochastically dominates at least one other sample. The test does not identify where this stochastic dominance occurs or for how many pairs of groups stochastic dominance obtains. The null hypothesis states that all months (or quarters, respectively) have the same mean. Under this hypothesis the test statistic follows a χ^2 distribution. When this hypothesis is rejected, it is assumed that time series values differ significantly between periods

The test is implemented in the class KruskalWallisTest. To be noted the differencing is not necessary.

TsData input = Data.P;
TramoSeatsSpecification rsafull=TramoSeatsSpecification.RSAfull;
// Process
IProcResults rslts = TramoSeatsProcessingFactory.process(input, rsafull);

TsData sa = rslts.getData("sa_cmp", TsData.class);
TsData irr= rslts.getData("i_cmp", TsData.class);
        
FriedmanTest ftsa=new FriedmanTest(sa.delta(1));
System.out.println(ftsa.getPValue());
// remove the mean if the decomposition is multiplicative
FriedmanTest fti=new FriedmanTest(irr.minus(1));
System.out.println(fti.getPValue());
        
KruskalWallisTest kwsa=new KruskalWallisTest(sa);
System.out.println(kwsa.getPValue());
KruskalWallisTest kwirr=new KruskalWallisTest(irr);
System.out.println(kwirr.getPValue());

Qs test (auto-correlations at seasonal lags)

This test checks the correlation between the actual observation and observation lagged by one and two years.
The test is a slightly modified Ljung-Box test (distributed as a χ^2). The series have to be differenced if need be.

The test is implemented in the class QSTest, which calls the more general ec.tstoolkit.stats.LjungBoxTest

// Create/get the ts (for example...)
TsData input = Data.P;
// Using a pre-defined specification
X13Specification rsa5 = X13Specification.RSA5;
// Process
IProcResults rslts = X13ProcessingFactory.process(input, rsa5);
TsData sa = rslts.getData("sa_cmp", TsData.class);
TsData irr = rslts.getData("i_cmp", TsData.class);
StatisticalTest lbsa = QSTest.test(sa.delta(1));
System.out.println(lbsa.getPValue());
// remove the mean if the decomposition is multiplicative
StatisticalTest lbirr = QSTest.test(irr.minus(1));
System.out.println(lbirr.getPValue());

Combined test

The CombinedSeasonalityTest implements the test developed in X12-Arima for detecting the presence of a significant seasonality. It uses information coming from a seasonal adjustment.

The test is applied on the SI ratio, taking into account the mode of the seasonal decomposition (additive or multiplicative). In X12-Arima, the test is typically applied on the table D8. In other methods (Tramo-Seats...), you should use roughly corresponding information (sum of the seasonal and irregular components, without deterministic effects). Default implementations of seasonal adjustment methods should provide the SI ratio by means of the si_cmp key.

// Create/get the ts (for example...)
TsData input = Data.P;
// Using a pre-defined specification
X13Specification rsa5 = X13Specification.RSA5;
// Process
IProcResults rslts = X13ProcessingFactory.process(input, rsa5);
// Get D8
TsData si = rslts.getData("d8", TsData.class);
// Get the decomposition mode
DecompositionMode mode = rslts.getData("mode", DecompositionMode.class);
// Create the test
CombinedSeasonalityTest test = new CombinedSeasonalityTest(si, mode.isMultiplicative());
// Retrieve the summary of the test
System.out.println(test.getSummary());
// Retrieve some details
SeasonalityTest stableSeasonality = test.getStableSeasonality();
System.out.println(stableSeasonality.getPValue());

// The same for Tramo-Seats
// Using a pre-defined specification
TramoSeatsSpecification rsafull=TramoSeatsSpecification.RSAfull;
// Process
rslts = TramoSeatsProcessingFactory.process(input, rsafull);
// Get SI
si = rslts.getData("si_cmp", TsData.class);
// Get the decomposition mode
mode = rslts.getData("mode", DecompositionMode.class);
// Create the test
test = new CombinedSeasonalityTest(si, mode.isMultiplicative());
// Retrieve the summary of the test
System.out.println(test.getSummary());
// Retrieve some details
stableSeasonality = test.getStableSeasonality();
System.out.println(stableSeasonality.getPValue());