1

I want to calculate weighted covariance matrix where the weights are given to each element (entry, cell) of the original data matix, and not to rows (as done by cov.wt in stats).

The issue had been discussed on CrossValidated here, but no actual implementation (e.g. in a form of R code) was presented. Some solutions are offered by this and this papers, but are impenetrable to me and I lack the skill to code them.

Is there a package or a function that does it? Or, would anybody be able to come up with a couple of lines of code that can do it?

Petr Keil
  • 116
  • 3
  • To clarify: do you want to do PCA with weights or do you really need to compute covariance matrix? The algorithm of Gabriel & Zamir directly finds a low-rank approximation to $X$ given weights $W$; it's not computing a "weighted covariance matrix". I am not sure what it even means to compute covariance matrix with weights. – amoeba Nov 06 '15 at 11:22
  • Ultimately, yes, I'd like to compute PCA with weights, and for that I need a weighted covariance matrix. But as I said, I need to weight each observation in the original dataset -- I have a measure of error associated with each data point, which I want to put into the analysis as a weight. My intuition tells me that if I can weight rows in the original dataset using `cov.wt`, I should also be able to weight the individual data entries. But I struggle to actually do this weighting. And the math in the papers that describe it is impenetrable. – Petr Keil Nov 06 '15 at 13:10
  • Yes, I understand that your weights are cell-specific. My point is that to do a "weighted PCA" (as described in Gabriel & Zamir or in a similar way) you do **not** need to compute a "weighted covariance matrix" first. As I said, I am not even sure how to define a "weighted covariance matrix". That's why I am trying to clarify if your question is actually primarily about weighted PCA (and whether one needs a cov matrix for that or not is secondary), or if it is primarily about weighted cov matrix (and whether to do PCA with it or not is secondary). – amoeba Nov 06 '15 at 14:09

0 Answers0