Saturday, March 24, 2012

Testing for seasonal unit roots in R

I will explain seasonal unit root testing in R. Briefly, R is a language for statistical computing. It is very similar to MATLAB, SAS...etc. The website is http://www.r-project.org

Suppose that a our dataset is seasonal and that we intend to use a seasonal ARIMA model. We need to test our time to see if it is seasonal integrated.

Version 3.x of the "forecast" R package has a new function for testing for seasonal unit roots. The function is nsdiffs().

R also comes with a US Accidental Deaths dataset.

So to follow along, open up R and type the following:

>USAccDeaths

You will then see the US Accidental Deaths dataset. You can see that it is monthly.

Now install the "forecast" R package from CRAN. Then load it.

To view the help file for the nsdiffs() type:

>?nsdiffs

It will bring up a page that is for both nsdiffs and ndiffs.

There are two tests that have been implemented in nsdiffs, the OCSB test (default) and the Canova-Hansen test. You can also speicify the seasonal period of your dataset. USAccDeaths is a TS object and the seasonal period or "frequency" is a data member of the USAccDeaths/TS object.

To perform the OCSB test:

>nsdiffs(USAccDeaths)

To perform the Canova-Hansen test:

>nsdiffs(USAccDeaths, test="ch")

The ouput: "1" means that there is a seasonal unit root and "0" that there is no seasonal unit root.

You will notice that the two different tests give two different answers. This is because the Canova-Hansen test is less likely to decide in favour of a seasonal unit root than the OCSB test. Unlike the Canova-Hansen test, the OCSB test has a null hypothesis of a unit root. The USAccDeaths dataset is "on the edge". Osborn (1990) writes that when in doubt, it's better to seasonally difference.



Bibliography:
Osborn, DR (1990) "A survey of seasonality in UK macroeconomic variables", International Journal of Forecasting 6(3):327-336

Osborn DR, Chui APL, Smith J, and Birchenhall CR (1988) "Seasonality and the order of integration for consumption", Oxford Bulletin of Economics and Statistics 50(4):361-377.

Canova F and Hansen BE (1995) "Are Seasonal Patterns Constant over Time? A Test for Seasonal Stability", Journal of Business and Economic Statistics 13(3):237-252.

No comments:

Post a Comment