在 R 中将多元 XTS 转换为 TS

Convert multivariate XTS to TS in R

我想计算多元时间序列数据集的小波变换。我计划使用 wavethresh 包,特别是 modwt() 函数。此函数的帮助文件指定对象是 "A univariate or multivariate time series. Numeric vectors, matrices and data frames are also accepted."

目前我的数据集是 xts zoo 格式,时间间隔为 15 分钟,我想将它转换为 ts,但我遇到了很大的困难。

我试过以下方法:

modwtCoeff <- modwt(as.ts(wideRawXTS,
+                           start = head(index(wideRawXTS), 1), 
+                           end = tail(index(wideRawXTS), 1),
+                           frequency = 1),
+                     filter = "la8",
+                     n.levels = "10",
+                     boundary = "periodic",
+                     fast = TRUE)

> class(wideRawXTS)
[1] "xts" "zoo"

其中 head(index(wideRawXTS,1),1) returns "2017-01-20 16:30:00 GMT"tail(index(wideRawXTS,1),1) returns "2017-02-03 16:00:00 GMT"

由于上面的行,我收到以下错误:

Error in ts(coredata(x), frequency = frequency(x), ...) : 
  formal argument "frequency" matched by multiple actual arguments

错误出在 xts 到 ts 的转换上,因为我删除了 modwt 包装函数,但我仍然得到同样的错误。在进一步谷歌搜索后,我看到了这篇文章 https://www.r-bloggers.com/preventing-argument-use-in-r/,但我没有完全理解它。我的猜测是我可能需要将转换分解为单独的步骤以避免在 as.ts 函数中使用某些参数时出错。

谁能给我一些指导,说明我在转换过程中出了什么问题?为了提供一个可重现的例子,这里是一个 link 到 wideRawXTS 对象的输入。

计算频率的一般函数是:

frequency = number_of_events / time_interval

由于您的数据有 1343 行,时间间隔为 14 天,频率取决于您的时间单位。

时间单位:天

在这种情况下,频率为:

 1343/14 = 95.93 => 96

也就是说,您每天进行 96 次测量。

时间单位:小时

在这种情况下,频率为:

 1343/(14*24) = 3.99 => 4

也就是说,您每小时进行 4 次测量。

时间单位:15分钟

在这种情况下,频率为:

 1343/(14*24*4) = 0.999 => 1

也就是说,您每 15 分钟测量一次。