# Weighted PCA with MultivariateStats.jl

**URL:** <https://discourse.julialang.org/t/weighted-pca-with-multivariatestats-jl/113525>\
**Category:** Statistics\
**Created:** [April 26, 2024, 9:26am UTC](https://discourse.julialang.org/t/weighted-pca-with-multivariatestats-jl/113525 "2024-04-26T09:26:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![njacki](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@njacki](https://discourse.julialang.org/u/njacki)\
**Post date:** [April 26, 2024, 9:26am UTC](https://discourse.julialang.org/t/weighted-pca-with-multivariatestats-jl/113525/1 "2024-04-26T09:26:54Z")

</div>

Hi,

I want to perfrom PCA on my dataset and assign possible different weights to my variables. According to [Jolliffe (2002)](https://link.springer.com/book/10.1007/b98835), this can be easily done when the weighting matrix can be factorized, i.e., W\_{ij} = \omega\_i \phi\_j. Where \boldsymbol{\phi} weigths the experiments and \boldsymbol{\omega} weigths the _pixels_ inside each experiment.

In this case, I guess that computing the weighted PCA of `X` (each column is an experiment) using the package is reduced to

```julia
X_weighted = sqrt.(ϕ)' .* X .* sqrt.(ω)
M = fit(PCA, X_weighted; kwargs...)

```

Is it correct to proceed like this? And when I want to project existing (or new) experiments onto the new lower-dimensional subspace, should I project `X_new` or `X_new .* sqrt.(ω)` (same question for the reconstruction)?  
What about the eigenvectors (projection matrix), should I divide them by the square roots of the weigths to grasp their true meaning (i.e., `1./sqrt.(ϕ)' .* M.proj .* 1./sqrt.(ω)`)?

Thanks in advance,  
J.
