Weighted covariance, how to compute?


If d is data set and k,l=size(d)
cov = d’*d/k-mean(d,1)’*mean(d,1)

It is nice formula ,

But how to compute the cov if any row is weighted by vector w ?




Thx, but i need algebraic formula (to large matrix for this way). Somebody can help ?


The methods above do not have a lot of overhead, but if you need online methods,

can also do covariance matrices very efficiently.


Thanks, but I have really huge matrix, only algebraic way is ok for it !
Somebody can help ?


If you can share how the methods mentioned by @Tamas_Papp failed and what else you have tried you are more likely to get a concrete answer. How big is your really huge matrix?


o = CovMatrix(l) # fue minutes …
Series(y,o) # nothing doing

Julia 6.0
win7, 8 core in machine, Ram =8G
y is only sample
my matrix is sparse size : 10^7 x 30*10^4

I am looking for algebraic formula because i can use pmap


Are those numbers right? Even if your data is sparse, the covariance matrix will be dense, and require 670GB to store.

julia> 300_000^2 * 8 / 1024 ^3 


I know, and Im looking for this algebraik formula .

W dniu 2017-11-24 o 22:23, Josh Day pisze:


Why is this a Julia question then? In any case, see Wikipedia.

The libraries I linked above implement two-pass and online algorithms for this statistic. I imagine you would be much better off using them than rolling your own.