简体   繁体   English

将时间序列分析功能应用于xts对象时出现错误

[英]Getting Error when applying time-series analysis function to an xts object

I want to perform a time series analysis on a daily data stored as xts object. 我想对存储为xts对象的每日数据执行时间序列分析。 I think not all functions and models that work with ts objects work also with xts ones. 我认为并非所有适用于ts对象的函数和模型都适用于xts的函数和模型。 I chose to create xts object in the first place because I also have time in my data (For example this is one instance of the DateTime column "2012-08-25 06:00:00") so I created my object this way: 我选择首先创建xts对象是因为我的数据中也有时间(例如,这是DateTime列“ 2012-08-25 06:00:00”的一个实例),因此我以这种方式创建了对象:

myXtsObj = as.xts(mydata$var1, order.by = mydata$DatetimeVar)

I keep receiving the same error when I want to use some functions such as: 当我想使用某些功能时,我不断收到相同的错误:

ma(myXtsObj, order = 4, centre = T) 
ets(myXtsObj)

Both ets and ma functions are not working which basically I am using to detect trends and seasonality in the data. ets和ma函数都无法正常工作,基本上我正在使用它们来检测数据的趋势和季节性。

My questions: 我的问题:

1) I am not sure what is the correct value for "order" argument for my daily data in "ma" function. 1)我不确定“ ma”函数中日常数据的“ order”参数的正确值是多少。 Any help? 有什么帮助吗?

2) The error appearing when I am using the two function and also when I try to convert the xts object to ts object using as.ts is: 2)当我使用两个函数时,以及尝试使用as.ts将xts对象转换为ts对象时出现的错误是:

Error in if (frequency > 1 && abs(frequency - round(frequency)) < ts.eps) frequency <- round(frequency) : missing value where TRUE/FALSE needed if(频率> 1 && abs(频率-轮(频率))<ts.eps)中的错误频率<-轮(频率):需要TRUE / FALSE的缺失值

What could be causing this error? 是什么导致此错误?

As the help files state, both ma() and ets() require ts objects as the first argument, not xts objects. 作为帮助文件的状态, ma()ets()都需要ts对象作为第一个参数,而不是xts对象。

If you want to estimate a trend, setting order=7 in ma() will remove the day-of-week seasonality. 如果要估计趋势,则在ma()中将order=7设置order=7将删除星期几的季节性。 A better method would be to use stl() or forecast::mstl() 更好的方法是使用stl()forecast::mstl()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM