TYL
TYL

Reputation: 1637

Augmented Dickey Fuller test for Time series with NA in r

Does anyone have any suggestions to implement the augmented dickey fuller test in r on a time series with NA values?

The adf.test function does not accept NA values.

Any help is appreciated!

Upvotes: 5

Views: 7103

Answers (2)

Yasmina
Yasmina

Reputation: 1

Solved it with:

data = data %>% dplyr::filter(!is.na(column))

Upvotes: 0

Martin
Martin

Reputation: 332

Another r command would be ur.df (urca package).

But your problem is not related to coding. You cant use the ADF or any other stationary test on your time series. The test uses the lag structure and can therefore not be used. Have a look here to show how you could modify your data for the test and how this affects your test power.

1. "Close up" the gaps in the series. To consider a very simple example, suppose that we have data for y1, y2,....., yj-1, yj+1,...., yT (with yj missing). Then shift the (j+1)th observation back to the jth position, the (j+2)th observation back to the (j+1)th position, etc. The resulting series will then run "continuously" for (T-1) observations.

2. Replace the missing observation(s) with the last recorded observation before the gap. For the example above, the series will then have T observations: y1, y2,....., yj-1, yj-1, yj+1,......., yT.

3. Fill in a gap by linearly interpolating between the last recorded recorded observation before the gap, and the first recorded observation after the gap. For the example above, the series will then have T observations: y1, y2,....., yj-1, yj*, yj+1,......., yT . Here, yj* = yj-1 + (yj+1 - yj-1) / 2.

Ryan, Giles 1998

Upvotes: 3

Related Questions