Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ndiffs

Number of differences required for a stationary series


Description

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

Usage

ndiffs(
  x,
  alpha = 0.05,
  test = c("kpss", "adf", "pp"),
  type = c("level", "trend"),
  max.d = 2,
  ...
)

Arguments

x

A univariate time series

alpha

Level of the test, possible values range from 0.01 to 0.1.

test

Type of unit root test to use

type

Specification of the deterministic component in the regression

max.d

Maximum number of non-seasonal differences allowed

...

Additional arguments to be passed on to the unit root test

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.

Value

An integer indicating the number of differences required for stationarity.

Author(s)

Rob J Hyndman, Slava Razbash & Mitchell O'Hara-Wild

References

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, D.R. (1990) "A survey of seasonality in UK macroeconomic variables", International Journal of Forecasting, 6:327-336.

Phillips, P.C.B. and Perron, P. (1988) "Testing for a unit root in time series regression", Biometrika, 72(2), 335-346.

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)
ndiffs(diff(log(AirPassengers), 12))

forecast

Forecasting Functions for Time Series and Linear Models

v8.14
GPL-3
Authors
Rob Hyndman [aut, cre, cph] (<https://orcid.org/0000-0002-2140-5352>), George Athanasopoulos [aut], Christoph Bergmeir [aut] (<https://orcid.org/0000-0002-3665-9021>), Gabriel Caceres [aut], Leanne Chhay [aut], Mitchell O'Hara-Wild [aut] (<https://orcid.org/0000-0001-6729-7695>), Fotios Petropoulos [aut] (<https://orcid.org/0000-0003-3039-4955>), Slava Razbash [aut], Earo Wang [aut], Farah Yasmeen [aut] (<https://orcid.org/0000-0002-1479-5401>), R Core Team [ctb, cph], Ross Ihaka [ctb, cph], Daniel Reid [ctb], David Shaub [ctb], Yuan Tang [ctb] (<https://orcid.org/0000-0001-5243-233X>), Zhenyu Zhou [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.