我正在尝试编码滚动的马哈拉诺比斯距离,但是我有一些警告,它会导致错误的支出
Outpout = as.data.frame(NULL)
i = 1
window = 252
logret_df = as.data.frame(log_ret)
colnames(logret_df) = rownames(logret_df) = NULL
while (i < nrow(logret_df) - window) {
maha_dist = mahalanobis(logret_df[i:(i + window),], rowMeans(logret_df[i:(i+window),]), cov(logret_df[i:(i + window),]))
Outpout = rbind(Outpout, maha_dist)
i = i + 1
}
这就是我的50 or more warnings (use warnings() to see the first 50
In sweep(x, 2L, center) : STATS is longer than the extent of 'dim(x)[MARGIN]
dim(logret_df)
2464 50
有什么想法吗?谢谢