StationarityTests

by Luci Ellis

This notebook is sets up several standard tests of stationarity and non-stationarity in time series.

Reference

Title

StationarityTests

Author

Luci Ellis

Summary

This notebook is sets up several standard tests of stationarity and non-stationarity in time series, including the Kwiatowski et. al. (1992) KPSS test..

Copyright

© Copyright 1997, Luci Ellis

Permission is granted to distribute this file for any purpose except for inclusion in commercial software or program collections. This copyright notice must remain intact..

Notebook Version

1.0

Mathematica Version

3.0

History

Version 1.0, first implementation of KPSS test.

Keywords

Stationarity, non-stationarity, integration, cointegration

Source

KPSS test from Kwiatkowski, D., Phillips, P.C.B., Schmidt, P. and Shin, Y. (1992),“Testing the null hypothesis of stationarity against the alternative of a unit root: how sure are we that economic time series have a unit root?”, Jounal of Econometrics, 54, 159–178.

Warnings

description of global effects, incompatibilities

Note: all cells marked as "InitializationCell" will be written to the Auto-Save package. This package can then be read in programs that use it with Needs["Template`"]. Cells not intended to belong to the package should not have this property.

Limitation

special cases not handled, known problems

Discussion

description of algorithm, information for experts

Requirements

"Statistics`LinearRegression`", "Statistics`Common`MultivariateCommon`",
"Statistics`Common`RegressionCommon`", "Statistics`ConfidenceIntervals`",
"Statistics`Common`PopulationsCommon`", "Statistics`NormalDistribution`",
"Statistics`Common`DistributionsCommon`", "Statistics`DescriptiveStatistics`",
"Graphics`Animation`"

Setup

This section contains commands needed to load the corresponding package. It may be omitted for notebooks that are used only to generate an auto-save package.

Interface

This part declares the publicly visible functions, options, and values.

Set up the package context, including public imports

BeginPackage["EconGroup`StationarityTests`", "Statistics`LinearRegression`", "Statistics`Common`MultivariateCommon`",
"Statistics`Common`RegressionCommon`", "Statistics`ConfidenceIntervals`",
"Statistics`Common`PopulationsCommon`", "Statistics`NormalDistribution`",
"Statistics`Common`DistributionsCommon`", "Statistics`DescriptiveStatistics`",
"Graphics`Animation`"]

Usage messages for the exported functions and the context itself

StationarityTests::usage = "StationarityTests.m is a package that provides tests of stationarity / non-stationarity for vectors of numeric data."

KPSStest::usage = "KPSStest[resids, l] computes the test statistic from Kwiatowski et. al. (1992) for a vector of numeric data, with a null hypothesis of stationarity, I(0)."

ResidualData::usage = "ResidualData is an option to KPSStest, indicating if the data input is residuals from an existing equation or not. If ResidualData is True (the default), the test is performed on the existing data. If ResidualData is False, the input data is first regressed on a constant and a linear trend, and the test is performed on the resulting residuals."

Error messages for the exported objects

Implementation

This part contains the actual definitions and any auxiliary functions that should not be visible outside.

Begin the private context (implementation part)

Begin["`Private`"]

Definition of auxiliary functions and local (static) variables

Definition of the exported functions

KPSStest[]

Options[KPSStest]={ResidualData->True}

SetOptions[KPSStest,ResidualData->True]

\(KPSStest[data : {__?NumericQ}, ℓ_Integer, opts___?OptionQ]\ 
       := \ 
Module[{resids, restrue}, 
        restrue\  = 
          \((ResidualData /. Flatten[{opts}])\) /. Options[KPSStest]\ ; \ 	

        		resids\  = \ 
          If[restrue, data, 
            FitResiduals /. 
              Regress[data, {1, x}, {x}, 
                RegressionReport -> {FitResiduals}]]; 

        With[{𝒯 = Length[resids]}, 
          Plus@@\((
                \((\(\((Plus\ @@Drop[resids, \(-#\)])\)&\)\ /@\ 
                      Range[𝒯])\)\^2)\)÷\((
              \(𝒯\^2\) 
                \((\(1\/𝒯\) Plus@@\((resids\^2)\) + 
                    \(2\/𝒯\) 
                      \((Plus@@
                          \((\(\((Plus@@
                                    \((\((1 - #\/\(ℓ + 1\))\) 
                                        \((Drop[resids, #]\ 
                                        Drop[RotateRight[resids, #], #])\))\))
                                  \)&\)/@Range[ℓ])\))\)\ )\))\)]]\)

End the private context

End[ ]

Epilog

This section protects exported symbols and ends the package.

Protect exported symbol

Protect[ KPSStest ]

End the package context

EndPackage[ ]

Examples, Tests

Examples, tests for the use of the package can go here.