我有一个看起来像这样的向量:
> y
[1] 6.7 5.3 3.3 6.7 3.3 4.7 4.7 6.7 3.3 6.7
我试图h = 3
使用以下公式计算时移时的估计自协方差:
这就是我所做的,我想知道有没有比硬编码更简单的方法:
> 1/10 * (
+ (y[4] - mean(y))*(y[1] - mean(y)) +
+ (y[5] - mean(y))*(y[2] - mean(y)) +
+ (y[6] - mean(y))*(y[3] - mean(y)) +
+ (y[7] - mean(y))*(y[4] - mean(y)) +
+ (y[8] - mean(y))*(y[5] - mean(y)) +
+ (y[9] - mean(y))*(y[6] - mean(y)) +
+ (y[10] - mean(y))*(y[7] - mean(y))
+ )
[1] -0.04848