Testing Skewness in Time Series data using R but getting “Error: NCOL(x) == 1 is not TRUE”

别来无恙 提交于 2019-12-13 21:45:58

问题


I am using the Dow Jones Dataset and I am trying to test skewness. So far this is the code:

library(tseries)
library(zoo)
library(reshape2)
library(fBasics)

dow = read.table('dow_jones_index.data', header=T, sep=',')
# create time series
dow <-  read.table('dow_jones_index.data', header=T, sep=',', stringsAsFactors = FALSE)
# delete $ symbol and coerce to numeric
dow$close <-  as.numeric(sub("\\$", "",dow$close))
tmp <- dcast(dow, date~stock, value.var = "close")
#tmp[,-1] means it's removing the first column (date) of tmp
dowts <- as.zoo(tmp[,-1], as.Date(tmp$date, format = "%m/%d/%Y"))

#compute simple returns ret = (p_t-p_(t-1))/p_(t-1) 
dowgrowth = (dowts-lag(dowts, k=-1))/lag(dowts, k=-1) 

#Skewness test 
skew_test = skewness(dowgrowth)/sqrt(6/length(dowgrowth)) 

Everything runs fine except the skew_test line which gives me an error of:

Error: NCOL(x) == 1 is not TRUE

Not sure where to go from here. Thanks.

来源:https://stackoverflow.com/questions/35113719/testing-skewness-in-time-series-data-using-r-but-getting-error-ncolx-1-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!