我有一个 xts 对象,其中包含 12 个变量,时间间隔为 15 分钟。
> summary(wideRawXTSscaled)
Index DO0182U09A3 DO0182U09B3 DO0182U09C3 DO0182U21A1 DO0182U21A2
Min. :2017-01-20 16:30:00 Min. :-1.09338 Min. :-1.0666 Min. :-0.9700 Min. :-1.2687 Min. :-1.00676
1st Qu.:2017-01-24 04:22:30 1st Qu.:-0.60133 1st Qu.:-0.6675 1st Qu.:-0.6009 1st Qu.:-0.4522 1st Qu.:-0.48525
Median :2017-01-27 16:15:00 Median :-0.38317 Median :-0.2742 Median :-0.1761 Median :-0.2127 Median :-0.27482
Mean :2017-01-27 16:15:00 Mean : 0.00000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.00000
3rd Qu.:2017-01-31 04:07:30 3rd Qu.: 0.08221 3rd Qu.: 0.2922 3rd Qu.: 0.1125 3rd Qu.: 0.1248 3rd Qu.: 0.05455
Max. :2017-02-03 16:00:00 Max. : 3.33508 Max. : 9.2143 Max. : 5.8473 Max. :18.4909 Max. :12.21382
DO0182U21A3 DO0182U21B1 DO0182U21B2 DO0182U21B3 DO0182U21C1 DO0182U21C2 DO0182U21C3
Min. :-1.09339 Min. :-1.0268 Min. :-0.9797 Min. :-1.0853 Min. :-1.3556 Min. :-1.15469 Min. :-1.2063
1st Qu.:-0.33919 1st Qu.:-0.6020 1st Qu.:-0.5597 1st Qu.:-0.6692 1st Qu.:-0.5600 1st Qu.:-0.37291 1st Qu.:-0.3460
Median :-0.21082 Median :-0.3389 Median :-0.3466 Median :-0.3828 Median :-0.2138 Median :-0.16183 Median :-0.1635
Mean : 0.00000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.00000 Mean : 0.0000
3rd Qu.:-0.01826 3rd Qu.: 0.2105 3rd Qu.: 0.2486 3rd Qu.: 0.5624 3rd Qu.: 0.1992 3rd Qu.: 0.08052 3rd Qu.: 0.1363
Max. :12.69083 Max. : 7.7314 Max. : 9.2900 Max. : 7.3540 Max. :13.7427 Max. :13.76166 Max. :15.8086
我希望计算每个时间间隔的每个变量之间的相关性。由于我有 12 个变量,我希望我的 xts 对象中的 15 分钟数据点中的每一个都有一个 12 x 12 矩阵。
对于相关计算,我使用以下代码:
wideRawXTSscaledCorr <- rollapplyr(wideRawXTSscaled, 10, cor, by.column = FALSE)
上面代码中的“10”使用 10 个时间序列值来计算相关矩阵,因此我将在我的开头有 9 个 NA 值,wideRawXTSscaledCorr
相关值在第 10 个返回。
> wideRawXTSscaledCorr[1:10,1:5]
[,1] [,2] [,3] [,4] [,5]
2017-01-20 16:30:00 NA NA NA NA NA
2017-01-20 16:45:00 NA NA NA NA NA
2017-01-20 17:00:00 NA NA NA NA NA
2017-01-20 17:15:00 NA NA NA NA NA
2017-01-20 17:30:00 NA NA NA NA NA
2017-01-20 17:45:00 NA NA NA NA NA
2017-01-20 18:00:00 NA NA NA NA NA
2017-01-20 18:15:00 NA NA NA NA NA
2017-01-20 18:30:00 NA NA NA NA NA
2017-01-20 18:45:00 1 0.1590656 0.2427391 0.1987761 -0.1026246
当我将滑动窗口的值更改为 <10 的任何值时,我会重复出现以下错误:
> wideRawXTSscaledCorr <- rollapplyr(wideRawXTSscaled, 7, cor, by.column = FALSE)
Warning messages:
1: In FUN(.subset_xts(data, (i - width + 1):i), ...) :
the standard deviation is zero
2: In FUN(.subset_xts(data, (i - width + 1):i), ...) :
the standard deviation is zero
3: In FUN(.subset_xts(data, (i - width + 1):i), ...) :
the standard deviation is zero
4: In FUN(.subset_xts(data, (i - width + 1):i), ...) :
the standard deviation is zero
5: In FUN(.subset_xts(data, (i - width + 1):i), ...) :
the standard deviation is zero
这是我可以用来查看这些错误是否仅仅是我的数据的症状的唯一测试,还是由于我犯的一些编码错误?有没有其他方法可以让我更深入地了解代码以查看哪些值导致了这些错误?