I have a really small time series dataset (21 yearly observations) and I want to check if my data is stationary.

ndiffs(TS, test="adf")

[1] 2

TSdiff2=diff(TS, differences=2)


    Augmented Dickey-Fuller Test

data: TSdiff2
Dickey-Fuller = -2.4232, Lag order = 2, p-value = 0.4112
alternative hypothesis: stationary

According to the explanation in this link [http://www.r-bloggers.com/time-series-analysis-using-r-forecast-package/][1] : "The null-hypothesis for an ADF test is that the data are non-stationary. So large p-values are indicative of non-stationarity, and small p-values suggest stationarity. Using the usual 5% threshold, differencing is required if the p-value is greater than 0.05.

So it seems that my time series is not stationary despite the fact that I used the ndiffs function to estimate the number of differences.


The function ndiffs allows for at most second order differencing by default (argument max.d=2), see the help file. Perhaps that is why it returns 2 (which indicates order of at least 2).

Consider the following example: generate a series that is integrated of order 3 and find its order of integration using the function ndiffs using the default maximum order:


It will suggest 2 for the raw series (incorrectly, and similarly to your case), 2 for the first difference of the series (correctly), 1 for the second difference (correctly) and 0 for the third difference (correctly).

Now allow for a greater maximum order of integration:


Now you are getting order 3 for the raw series, which is correct.

However, beware that economic and financial time series can rarely be argued to have an order of integration greater than 2 (this could be the motivation for the default value max.d=2).

| cite | improve this answer | |
  • $\begingroup$ Thank you very much for your response. I allowed for a greater maximum in the max.d argument and now the ndiffs gives the right answer. $\endgroup$ – Nikos Tavoularis Jun 17 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.