R:在 xts 对象上使用 stl() [英] R: using stl() on an xts object

查看:26
本文介绍了R:在 xts 对象上使用 stl()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 R 比较陌生,所以请耐心等待.我正在尝试掌握基本的不规则时间序列分析.

I'm relatively new to R so please bear with me. I'm trying to get to grips with basic irregular time-series analysis.

这就是我的数据文件的样子,大约有 40k 行.间距总是正好是 20 秒.

That's what my data file looks like, some 40k lines. The spacing is not always exactly 20sec.

Time, Avg
04/03/2015 00:00:23,20.24
04/03/2015 00:00:43,20.38
04/03/2015 00:01:03,20.53
04/03/2015 00:01:23,20.54
04/03/2015 00:01:43,20.53

 data <- read.zoo("data.csv",sep=",",tz='',header=T,format='%d/%m/%Y %H:%M:%S')

我很高兴按分钟汇总

data <- to.minutes(as.xts(data))

以打开"列为例

head(data[,1])
                    as.xts(data).Open
2015-03-04 00:00:43             20.24
2015-03-04 00:01:43             20.53
2015-03-04 00:02:43             20.47
2015-03-04 00:03:43             20.38
2015-03-04 00:04:43             20.05
2015-03-04 00:05:43             19.84

data <- data[,1]

这就是我崩溃的地方

fit <- stl(data, t.window=15, s.window="periodic", robust=TRUE)
Error in stl(data, t.window = 15, s.window = "periodic", robust = TRUE) : 
series is not periodic or has less than two periods

我在谷歌上搜索了错误消息,但我不太清楚.周期=频率吗?对于我的数据集,我希望季节性成分是每周一次.

I've googled the error message, but it's not really clear to me. Is period = frequency? For my dataset I would expect the seasonal component to be weekly.

frequency(data) <- 52
fit <- stl(data, t.window=15, s.window="periodic", robust=TRUE)                   
Error in na.fail.default(as.ts(x)) : missing values in object

?

head(as.ts(data))
[1] 20.24    NA    NA    NA    NA    NA

呃,什么?

我做错了什么?我必须如何准备 xts 对象才能将其正确传递给 stl()?

What am I doing wrong? How do I have to prepare the xts object to be able to properly pass it to stl()?

谢谢.

推荐答案

我提取了 xts_object 的数值并为 stl 函数构建了一个 ts 对象.然而,在这种情况下,xts_object 的时间戳完全被忽略.

I extract numeric values of xts_object and build a ts object for stl function. However the time stamps of xts_object is completely ignored in this case.

stl(ts(as.numeric(xts_object), frequency=52), s.window="periodic", robust=TRUE) 

这篇关于R:在 xts 对象上使用 stl()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆