Skip to content

Bug in Explained Variance Calculation? #24

@nicrie

Description

@nicrie

Thank you for sharing your open-source code! I've been diving into the code, along with the original publication by Harris et al., with the aim of understanding it better so I can implement it in Python.

So far, I've managed to get accurate results when it comes to the loadings. When I run the following R code

result <- gwpca(...)

the values in result$loadings match perfectly with what I've implemented on my end.

However, I've hit a roadblock when trying to compute the explained variance (specifically, result$var). I've gone through the R code step by step and confirmed that the singular values from the local PCAs match as expected.

But, there's a particular line in the code that's left me a bit puzzled here:

d1 <- (d/(sum(wt)^0.5))^2

I get the concept that the singular values $s_i$ relate to eigenvalues $\lambda_i$ through $\lambda_i = s_i^2/n$, wheren is the number of samples. So, in principle, I believe this line is meant to achieve that. The issue, however, is that the wt weights are initialized earlier within the loop, and after the loop completes, wt still refers to the weights of the last sample. Consequently, all singular values are being squared using only the weights from the last sample, rather than being adjusted individually based on the respective sample's weights.

I'm relatively new to GWPCA, and it's quite possible that I'm misinterpreting this line or missing some crucial details in the code. If that's the case, I apologize for any confusion and would greatly appreciate your insights in helping me understand and resolve this matter :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions