tmakino
tmakino

Reputation: 648

adf.test returning p > 0.99 with xts, but returning p < 0.01 with coredata(xts)

Here is the output:

library(tseries) # for adf.test function

adf.test(data)
Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = 11.1451, Lag order = 16, p-value = 0.99
alternative hypothesis: stationary

Warning message:
In adf.test(spread.princomp) : p-value greater than printed p-value

adf.test(coredata(data))
Augmented Dickey-Fuller Test

data:  coredata(data)
Dickey-Fuller = -4.031, Lag order = 16, p-value = 0.01
alternative hypothesis: stationary

Warning message:
In adf.test(coredata(spread.princomp)) :
p-value smaller than printed p-value

The underlying data is a numeric vector. People seem to be successful at applying adf.test with xts, so I'm not sure what I'm doing wrong. Please let me know what other information I can provide.

Upvotes: 3

Views: 1964

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176688

?adf.test says that x (the first argument) should be a numeric vector or time series. By "time series", it means a ts classed object, not any time-series class object. You should convert your xts object to a ts object before calling adf.test.

For example:

library(tseries)
library(xts)
data(sample_matrix)
x <- as.xts(sample_matrix[,1])
adf.test(as.ts(x))

Upvotes: 8

Related Questions