circstat / pycircstat

Toolbox for circular statistics with Python
MIT License
157 stars 42 forks source link

Surprising value for Fisher skewness with nonzero mean #58

Closed mwaskom closed 6 years ago

mwaskom commented 6 years ago

I find that the computation of Fisher skewness can produce surprising results. Large samples from a normal distribution with a nonzero mean are determined to have very large skew. For example,

import numpy as np
import pycircstat
alpha = np.random.normal(np.pi / 4, np.pi / 8, 100000)
pycircstat.skewness(alpha, mode="fisher")

gives a value of about -36.73.

I have a suspicion about what is happening. In the code, the mean is subtracted away from the centered second moment. But I think that should be the uncentered second moment. If I re-define the function to

from pycircstat import cdiff, moment
def fixed_skewness(alphas):
    theta = pycircstat.mean(alphas)
    mom = pycircstat.moment(alphas, p=2, cent=False)
    mu2, rho2 = np.angle(mom), np.abs(mom)
    return rho2 * np.sin(cdiff(mu2, 2 * theta)) / (1 - R)**(3. / 2)

Then fixed_skewness(alpha) gives a value of about 0.000875, which better matches my (linear) intuitions.

Additionally, on p.34 of Fisher, the centered skewness is defined in terms of \hat \mu_2, which I think is the notation for the uncentered moment, and not m_2, the centered second moment. Though I find the appearance and disappearance of primes in Fisher's notation confusing.

Does this make sense?

~Also if this is actually a bug, then the Fisher kurtosis is probably wrong too.~

Edit: actually, the Fisher Kurtosis uses the uncentered second moment.

fabiansinz commented 6 years ago

Hi @mwaskom , I just checked the book and we seem to implement it exactly as stated in there (skewness with centered, kurtosis with uncentered). I also checked Mardia and Jupp 2000, but their notation is even harder to understand. However, skewness should not depend on the location of the distribution. Therefore, I think you found a typo in the book by Fisher and the skewness really should use the uncentered moment.

Would you mind putting that in a pull request? If it's too much hassle for you I can do it as well. Let me know.

Love seaborn by the way. Thanks for writing it!