## How to check in R if time series is stationary?

Before we can fit an ARIMA model, our time series has to be stationary. Time series is stationary if its mean level and variance stay steady over time, or as explained by Hyndman and Athanasopoulos (2013): “[a] stationary time series is one whose properties do not depend on the time at which the series is observed”.

In this post, we will demonstrate several tools and tests to check stationary. We will employ a time series of monthly property prices per m² in Amsterdam, between September 2008 and July 2013. The following graph displays the original series. Our analysis will be run in R, with the packages ‘fpp‘ and ‘forecast

And here is the series after log transformation and seasonal differenced..

Now we are going to check stationary. We will start with the ACF and PACF graphs and check significant lags. Each of these graphs can be drawn with the following commands:

```
Acf(LogTimeSeriesDiff12)
Pacf(LogTimeSeriesDiff12)
```

Both graphs have a few significant lags but these die out quickly, so we can conclude our series is stationary.

Other tests are also available in these R packages to check stationary.

The Ljung-Box test examines whether there is significant evidence for non-zero correlations at lags 1-20. Small p-values (i.e., less than 0.05) suggest that the series is stationary.

The Augmented Dickey–Fuller (ADF) t-statistic test: small p-values suggest the data is stationary and doesn’t need to be differenced stationarity.

The Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test; here accepting the null hypothesis means that the series is stationarity, and small p-values suggest that the series is not stationary and a differencing is required.

All the tests indicate that our time series is stationary, so it’s time to move on to the next step and fit an ARIMA model..

Further reading:

* Makridakis Spyros, Wheelwright Steve C. and Hyndman Rob J. (1998) Forecasting – Methods and Applications, 3rd ed., John Wily and Sons, Inc.

* Hyndman Rob J. and Athanasopoulos George (2013) Forecasting: Principles and Practice, OTexts

Happy Analysing!

Questions? Comments? Drop us a line.. info@statosphere.com.au