# ndiffs

##### Number of differences required for a stationary series

Functions to estimate the number of differences required to make a given time series stationary. `ndiffs`

estimates the number of first differences and `nsdiffs`

estimates the number of seasonal differences.

- Keywords
- ts

##### Usage

```
ndiffs(x, alpha=0.05, test=c("kpss","adf", "pp"))
nsdiffs(x, m=frequency(x), test=c("ocsb","ch"))
```

##### Arguments

- x
- A univariate time series
- alpha
- Level of the test
- m
- Length of seasonal period
- test
- Type of unit root test to use

##### Details

`ndiffs`

uses a unit root test to determine the number of differences required for time series `x`

to be made stationary. If `test="kpss"`

, the KPSS test is used with the null hypothesis that `x`

has a stationary root against a unit-root alternative. Then the test returns the least number of differences required to pass the test at the level `alpha`

. If `test="adf"`

, the Augmented Dickey-Fuller test is used and if `test="pp"`

the Phillips-Perron test is used. In both of these cases, the null hypothesis is that `x`

has a unit root against a stationary root alternative. Then the test returns the least number of differences required to fail the test at the level `alpha`

.

`nsdiffs`

uses seasonal unit root tests to determine the number of seasonal differences required for time series `x`

to be made stationary (possibly with some lag-one differencing as well). If `test="ch"`

, the Canova-Hansen (1995) test is used (with null hypothesis of deterministic seasonality) and if `test="ocsb"`

, the Osborn-Chui-Smith-Birchenhall (1988) test is used (with null hypothesis that a seasonal unit root exists).

##### Value

- An integer.

##### References

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.

Dickey DA and Fuller WA (1979), "Distribution of the Estimators for Autoregressive Time Series with a Unit Root", *Journal of the American Statistical Association* **74**:427-431.

Kwiatkowski D, Phillips PCB, Schmidt P and Shin Y (1992) "Testing the Null Hypothesis of Stationarity against the Alternative of a Unit Root", *Journal of Econometrics* **54**:159-178.

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.

Osborn, D.R. (1990) "Seasonality and the order of integration in consumption", *International Journal of Forecasting*, **6**:327-336.

Said E and Dickey DA (1984), "Testing for Unit Roots in Autoregressive Moving Average Models of Unknown Order", *Biometrika* **71**:599-607.

##### See Also

##### Examples

```
ndiffs(WWWusage)
nsdiffs(log(AirPassengers))
ndiffs(diff(log(AirPassengers),12))
```

*Documentation reproduced from package forecast, version 3.24, License: GPL (>= 2)*