2013-05-08 61 views
3

這裏是輸出:adf.test返回P> 0.99 XTS,但返回P <0.01,與coredata(XTS)

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 

底層數據是數值向量。人們似乎成功地將adf.test與xts結合使用,所以我不確定我做錯了什麼。請讓我知道我可以提供什麼其他信息。

+0

您應該包括包'adf.test'的名稱。 – 2013-05-08 18:29:27

+0

這可能與snark領域的[近期線索](http://thread.gmane.org/gmane.comp.lang.r.finance/11441/focus=11470)有關。 – GSee 2013-05-08 18:34:29

+0

測試單位根的最好方法是使用'urca'包,它通常更安全。 – dickoa 2013-05-08 18:38:12

回答

7

?adf.testx(第一個參數)應該是數字向量或時間序列。通過「時間序列」,這意味着一個ts分類對象,而不是任何時間序列類對象。在致電adf.test之前,您應該將您的xts對象轉換爲ts對象。

例如:

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

謝謝Joshua,證實它可以和as.zoo()一起工作 – tmakino 2013-05-08 18:41:46

+2

@tmakino:是的,這是因爲'diff.zoo'和'diff.ts'沒有填充前導'NA',而'diff.xts'確實。 – 2013-05-08 18:45:28