Open stephaneguerrier opened 7 years ago
Regarding Cross-covariance, I attached a .r file containing a function I wrote. The Wavelet Cross-covariance (only consider the cross covariance of wc with lag = 0) can be calculated with following steps:
Apart from the wccv, the function also returns the variance of each wccv and its 95% CI. The variance is calculated based on the spectrum density (of the cross product of wc from different TS) evaluate at 0 (spectrum0 function from library(coda)). spectrum0() may give some warning messages when level j is large (less number of wc).
################################################### library(coda)
wccv = function(Xt){ num.ts = ncol(Xt) N = nrow(Xt) J = floor(log2(N)) - 1 wccv.mat = matrix(NA, num.ts(num.ts-1)/2, J) cov.mat = matrix(NA, num.ts(num.ts-1)/2, J) ci.low.mat = matrix(NA, num.ts(num.ts-1)/2, J) ci.high.mat = matrix(NA, num.ts(num.ts-1)/2, J) c = 0 for(i in 1:(num.ts-1)){ coe1 = modwt(Xt[,i]) for(j in (i+1):num.ts){ c = c+1 coe2 = modwt(Xt[,j]) for(k in 1:J){ wccv.mat[c,k] = mean((unlist(coe1[k])) * (unlist(coe2[k])))
cov.mat[c,k] = 1/(N - 2^k + 1) * spectrum0((unlist(coe1[[k]])*unlist(coe2[[k]])), max.freq = 0.5, order = 2, max.length = 130)$spec
ci.low.mat[c,k] = wccv.mat[c,k] + qnorm(0.025) * sqrt(cov.mat[c,k])
ci.high.mat[c,k] = wccv.mat[c,k] + qnorm(1-0.025) * sqrt(cov.mat[c,k])
}
}
} list(wccv = t(wccv.mat), wccv.cov = t(cov.mat), ci_low = t(ci.low.mat), ci_high = t(ci.high.mat)) }
Hi guys,
Once Issue #4 has been addressed the next part is to compute various statistics from the wavelet decomposition, here are the main ones:
Note that for all the quantities described above we will need to compute the point estimate together with its (estimated) variance.