1

我有两个大小不等的动物园对象(流入和流出)。流出值滞后流入某个未知的时间量。我想确定较小的流出对象(6行)和较大的流入对象(多行)之间的相关性,一次6行,从流入开始时间开始,递增1,并找到相关性最高的时期. 我认为这被称为“滑动窗口”比较。我尝试了许多不同的方法,但均未成功,使用“rollapply”函数执行此操作,但由于两个对象之间的大小差异而出现错误。希望有人会理解我要问的问题并可以提供解决方案。下面是我的部分数据和我如何尝试使用 rollapply 函数的示例。

> inflow
(03/14/13 07:00:00) 11.20451
(03/14/13 07:02:00) 11.03810
(03/14/13 07:04:00) 11.03012
(03/14/13 07:06:00) 11.09517
(03/14/13 07:08:00) 10.90878
(03/14/13 07:10:00) 11.23285
(03/14/13 07:12:00) 11.14890
(03/14/13 07:14:00) 11.17002
(03/14/13 07:16:00) 11.38342
(03/14/13 07:18:00) 11.70833
(03/14/13 07:20:00) 11.93776
(03/14/13 07:22:00) 12.17832
(03/14/13 07:24:00) 12.39648
(03/14/13 07:26:00) 12.24020
(03/14/13 07:28:00) 12.18667
(03/14/13 07:30:00) 12.45410
(03/14/13 07:32:00) 12.50012
(03/14/13 07:34:00) 12.54736
(03/14/13 07:36:00) 13.05010
(03/14/13 07:38:00) 13.06495
(03/14/13 07:40:00) 13.14084
(03/14/13 07:42:00) 12.92427
(03/14/13 07:44:00) 12.98699
(03/14/13 07:46:00) 12.84172
(03/14/13 07:48:00) 12.87263
(03/14/13 07:50:00) 12.51861
(03/14/13 07:52:00) 12.98763
(03/14/13 07:54:00) 12.31124
(03/14/13 07:56:00) 12.33696
(03/14/13 07:58:00) 12.49630
(03/14/13 08:00:00) 12.40648
(03/14/13 08:02:00) 11.87164
(03/14/13 08:04:00) 12.76058
(03/14/13 08:06:00) 12.50016
(03/14/13 08:08:00) 12.68696
(03/14/13 08:10:00) 12.88447
(03/14/13 08:12:00) 12.33336
(03/14/13 08:14:00) 13.06670
(03/14/13 08:16:00) 13.15070
(03/14/13 08:18:00) 12.82410
(03/14/13 08:20:00) 12.91953

流出2

(03/14/13 07:54:00) (03/14/13 07:56:00) (03/14/13 07:58:00) (03/14/13 08:00:00) (03/14/13 08:02:00) (03/14/13 08:04:00) 
           11.51110            11.11878            11.05775            11.11303            10.95417            10.98035

利用:

> test <- rollapply(inflow, width = 6, by = 1, FUN = cor(inflow, outflow))
Error in cor(inflow, outflow) : incompatible dimensions
4

1 回答 1

1

尝试这个:

rollapply(inflow, 6, cor, y = outflow)

这计算

value <- c( cor(inflow[1:6], outflow), cor(inflow[2:7], outflow), ...etc... )
ix <- seq(3, length = length(inflow) - 6 + 1)
zoo(value, time(inflow)[ix])

根据你想得到什么,你可能也需要这个align=论点。

于 2013-08-22T18:48:16.293 回答