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

trouble with correlation #79

Open
david-klindt opened this issue Apr 8, 2022 · 4 comments
Open

trouble with correlation #79

david-klindt opened this issue Apr 8, 2022 · 4 comments

Comments

@david-klindt
Copy link

Hi guys, thanks for this lovely repo!

I am having trouble with circular correlation between two circular variables. As you can see they are strongly correlated, but the correlation function returns nearly 0:

image

Here are the two signals if you want to try it:
timeseries: 1, 2

Is there a problem with the code or am I doing sth wrong?

@philippberens
Copy link
Contributor

It's also not what I would expect - I need to see whether I find time to debug it. Is there a chance you can run the Matlab version if it yields the same?

@david-klindt
Copy link
Author

That would be great :) Unfortunately, I don't have a Matlab license

@huangziwei
Copy link

huangziwei commented May 18, 2022

the current implementation (Jammalamadaka & SenGupta, 2001) subtracts the mean out of the original data, then compute the correlation, which turns out to be problematic for your data, because ts1 is more or less uniformly distributed, while ts2 is bimodal (more accurately, axial).

here's an alternative implementation (Fisher & Lee, 1983; Zar, 1999) without mean subtraction that can give you a r_{aa}=0.94557:

def aacorr(a: np.ndarray, b: np.ndarray) -> float:

    """Fisher & Lee (1983); Zar (1999) eq (27.43)
    
    a, b: np.array, (n, )
        circular data in radian

    raa: float
         angular-angular correlation 
    """
    aij = np.triu(a[: ,None] - a).flatten()
    bij = np.triu(b[: ,None] - b).flatten()

    num = np.sum(np.sin(aij) * np.sin(bij))
    den = np.sqrt(np.sum(np.sin(aij) ** 2) * np.sum(np.sin(bij) ** 2))

    raa = num / den

    return raa

@Macko94
Copy link

Macko94 commented Jul 26, 2022

Hi guys, thanks for this lovely repo!

I am having trouble with circular correlation between two circular variables. As you can see they are strongly correlated, but the correlation function returns nearly 0:

image

Here are the two signals if you want to try it: timeseries: 1, 2

Is there a problem with the code or am I doing sth wrong?

Hi David,
Make sure you convert your angular values from degrees to radians. I had the same issue and turned out that the problem was wrong units.
Cheers,

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

4 participants