Thursday, August 25, 2011

Testing for seasonal unit roots in R

EDIT:This article has been re-written and updated in my analytics blog:Testing for seasonal unit roots in R

Suppose that for our new life insurance product, we want to model and forecast accidental deaths in US. 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. This will be the topic of this insurance quant blog post.

We will be using R and I will assume that the reader knows about R and how it could be applied in insurance. Briefly, R is very similar to MATLAB, SAS...etc. The website is http://www.r-project.org
I know that I have not written a "formal introduction" to R or how it can be used to model insurance, but that will have to wait because I deem it more important to document new packages/features of those packages as they come out.

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

R also come with a US Accidental Deaths dataset that we will be discussing in the insurance blog post with our example life insurancer problem. Right, so we are starting a life insurance business and we want to forecast accidental deaths.

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. By the time youd read this, forecast version (at least) 3.01 should be available. Version 3.00 would also be sufficient to work through this post, but I strongly recommend 3.01.

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 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. This is becuase unlike the Canova-Hansen test, the OCSB test has a null hypothesis of a unit root. Further, Osborn (1990) writes that when in doubt, it's better to seasonally difference.

Enjoy this life insurance related post! :-)

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.

5 comments:

  1. Life Insurance will handle that your family will Receive financial support in your Absence. Put simply, Life Insurance protect your family with the money you have to have something happen to you.Life insurance activities, financial instruments for your family’s future is secure, even if your sad demise.Insurance Helpline provides best life insurance in NZ.Our customers have the added benefit of our expert knowledge and advice on what is best for their insurance.

    ReplyDelete
  2. Thank you very much, that was quite useful.

    ReplyDelete
  3. I read your post very carefully and glad to say that your post is very helpful.I have same website too.If you want to collect more knowledge about insurance then please visit our website.insurance news

    ReplyDelete
  4. i read your post very carefully and glad to say that your post is very helpful.
    I have some insurance website too. if you want to collect more knowledge
    than please visit our website.
    insurance news

    ReplyDelete
  5. I need to learn how to run seasonal unit root tests in r when the two packages earlier used for this purpose no more exist? the package forecast is also unable to help in this regard as the function nsdiffs() is no more available in R3.1.2.
    or can you guide me how to load the uroot package in R 3.1.2? downloading it from archieve and installing package through loca zipped files is also not working.
    thanks alot

    ReplyDelete