将数据更改为数字类型以确定哪个分布更适合

时间:2016-09-21 03:34:38

标签: r vector dataframe

我试图弄清楚哪种分布符合最佳对数股票回报。这是我的代码:

library(TTR)
sign="^GSPC"
start=19900101
end=20160101
x <- getYahooData(sign, start = start, end = end, freq = "daily")
x$logret <- log(x$Close) - lag(log(x$Close))
x=x[,6]

我想使用我从这个惊人的帖子https://stats.stackexchange.com/questions/132652/how-to-determine-which-distribution-fits-my-data-best获得的函数descdist(x, discrete = FALSE)但是r给了我这个错误:Error in descdist(x, discrete = FALSE) : data must be a numeric vector如何将我的数据转换为数字向量?? < / p>

dput(head(x))的输出是:

structure(c(NA, -0.00258888580664607, -0.00865029791190164, -0.00980414107803274, 
0.00450431207515223, -0.011856706127011), class = c("xts", "zoo"
), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date", tzone = "UTC", index = structure(c(631238400, 
631324800, 631411200, 631497600, 631756800, 631843200), tzone = "UTC", tclass = "Date"), .Dim = c(6L, 
1L), .Dimnames = list(NULL, "logret"))

1 个答案:

答案 0 :(得分:0)

使用x预处理as.numeric(na.omit(x)),或只是运行

descdist(as.numeric(na.omit(x)), discrete = FALSE)