Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fix for numerical instabilities for corr and partial_corr: z-normalize #411

Open
wolfgang-ganglberger opened this issue Mar 6, 2024 · 1 comment
Assignees

Comments

@wolfgang-ganglberger
Copy link

Hi Raphael,

Big fan of your work and of this package, thanks so much. I was wondering if you have thoughts on numerical stability. The correlation and partial correlation can run into numerical instabilities when scales of variables are very different (factor 1e5 difference approximately). The functions do throw an error and the p-value is set to nan, however one fix could be to z-normalize the data before performing the matrix computations. Correlation and partial correlation functions are independent of scale.

See the screenshot for an example.

I think the pro is that it makes computations usually more robust, perhaps preventing people to use wrong results when numerical instabilities occur.
A con might be it also does not solve all instabilities, e.g. if you have a variable with 0 standard deviation.

Screenshot

@raphaelvallat raphaelvallat self-assigned this Mar 7, 2024
@raphaelvallat
Copy link
Owner

Hi @wolfgang-ganglberger,

Thanks for your kind words and the detailed proposal!

I think that sounds like a good approach to me, we just need to make sure not to overwrite the input data with the z-scored version of the variables.

Please feel free to submit a PR and we can continue the conversation there!

Thanks
Raphael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants