neurodata / neurodata/hyppo

CCA Incorrect Statistics

Open
#413 1 comment 0 reactions 1 assignee View on GitHub

@Riccardo231 is already working on this.

Since Dec 22, 2024.

bug
Dominant language
Python
Stars
252
Forks
96
PR merge metrics
No merged PRs in 30d

Description

When d=1, correlation from CCA is same as absolute value of Pearsons. hyppo CCA does not return correct statistic. Similar issues with higher dimensions. I believe it has something to do with squaring of singular values.

Reproducing code example:
import numpy as np
from sklearn.cross_decomposition import CCA as CCA_sklearn
from hyppo.independence import CCA as CCA_hyppo

x = np.random.normal(size=(100, 1))
y = np.random.normal(size=(100, 1))

np.abs(np.corrcoef(x.T, y.T)[0, 1])
>>>> 0.04939641702196

cca_sklearn = CCA_sklearn(1)
np.corrcoef(*cca_sklearn.fit_transform(x, y), rowvar=False).diagonal(offset=1)[0]
>>>> 0.04939641702196002

cca_hyppo = CCA_hyppo()
cca_hyppo.statistic(x, y)
>>>> 0.0024400060146073806

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.