2
$\begingroup$

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)

adf.test(TSdiff2)

    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.

$\endgroup$

1 Answer 1

5
$\begingroup$

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:

set.seed(1)
x=cumsum(cumsum(cumsum(rnorm(1000))))
ndiffs(x)
ndiffs(diff(x,differences=1))
ndiffs(diff(x,differences=2))
ndiffs(diff(x,differences=3))

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:

ndiffs(x,max.d=5)
ndiffs(diff(x,differences=1),max.d=5)
ndiffs(diff(x,differences=2),max.d=5)
ndiffs(diff(x,differences=3),max.d=5)

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).

$\endgroup$
1
  • $\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$ Commented Jun 17, 2016 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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