Skip to content
Advertisement

Why doesn’t Johnson-SU distribution give positive skewness in scipy.stats?

The code below maps the statistical moments (mean, variance, skewness, excess kurtosis) generated by corresponding parameters (a, b, loc, scale) of the Johnson-SU distribution (johnsonsu).

For the range of loop values specified in my code below, no parameter configuration results in positive skewness, only negative skewness, even though it should be possible to parameterize the Johnson-SU distribution to be positively-skewed.

import numpy as np
import pandas as pd
from scipy.stats import johnsonsu

moments = ['mu','sd','sk','ku']
X = []
for a in np.arange(0.5,5,.5):
    for b in np.arange(0.5,5,.5):
        for c in np.arange(-0.5,0.5,.25): #loc
            for d in [1]: #scale
                mvsk = johnsonsu.stats(a,b,c,d,moments='mvsk')
                mvsk = [mvsk[i].tolist() for i in range(len(mvsk))]
                X.append([a,b,c,d]+mvsk)
X = pd.DataFrame(np.asarray(X), columns=['a','b','c','d']+moments)   

for m in moments:
    print(m, X[[m]].min().round(3).values[0], X[[m]].max().round(3).values[0])

The min and max moments printed are:

mu -29937.57 0.136
sd 0.053 48036174150.987
sk -414.36 -0.078
ku 0.221 41173.869

What would be better ranges to explore for the a, b, loc and scale parameters than what I have specified below? The documentation only says a and b must be positive, nothing about what loc and scale must be limited to.

Advertisement

Answer

On looking at the Wikipedia article and the source code, it looks to me like the parameter a can change the skewness. Try negative values of a. The documentation says a must be greater than zero, but on glancing at the formulas and the code, that appears to be a bug in the documentation, and actually a can be less than or equal to zero.

I’ve tried your program above, replacing the range for a with np.arange(-2.5, 2.5, .5). It runs without error (although there are warnings about imprecision in the results, which are also present in the original) and reports:

mu -202.147 548.542
sd 0.052 16114617.207
sk -414.352 402.646
ku 0.213 41173.867

PS. I’ve reported this as a bug to the Scipy project: https://github.com/scipy/scipy/issues/13353

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement