2012-12-14 55 views
4

我試圖運行一些xts數據auto.arima,但我得到以下錯誤:上XTS使用auto.arima對象

library(quantmod) 
library(forecast) 

getSymbols('^GSPC',from='2000-01-01') 
auto.arima(GSPC$GSPC.Close) 

Error in dimnames(cd) <- list(as.character(index(x)), colnames(x)) : 
'dimnames' applied to non-array 

我發現,如果我

close <- as.ts(GSPC$GSPC.Close) 

然後auto.arima不會返回錯誤。但之後我丟失了與xts對象關聯的日期信息。有沒有辦法將數據保存爲xts並仍然運行該功能?

我注意到例如acf(GSPC$GPSC.Close)pacf()不會給出錯誤。

+1

如果它不工作,不通過'coredata使用XTS對象,但出口() '轉換爲矩陣,可能會使用'as.data.frame()'進行轉換。 –

回答

1

我建議你在auto.arima參數列表轉換GSPC$GSPC.Closetsvector,或者matrix

auto.arima(as.ts(Cl(GSPC))) 
auto.arima(coredata(Cl(GSPC))) # Dirk's suggestion