user248237
user248237

Reputation:

how kurtosis is calculated in scipy?

I have this code to calculate kurtosis (http://mathworld.wolfram.com/Kurtosis.html) using my own code and I compare it to scipy.stats.kurtosis

a = array([   1. ,    2. ,    2.5,  400. ,    6. ,    0. ])
#kurtosis (gives: 4.19886)
print (sum((a - np.mean(a)) ** 4)/len(a)) / np.std(a)**4
# scipy kurtosis (gives: 5.996677)
print scipy.stats.kurtosis(a,bias=False)

why is scipy giving a different result? I followed the definition in mathworld.

Upvotes: 5

Views: 5810

Answers (1)

mtrbean
mtrbean

Reputation: 903

If you read the documentation of scipy's kurtosis function, scipy is calculting Excess Kurtosis by default (with the minus 3):

scipy.stats.kurtosis(a, axis=0, fisher=True, bias=True)

Computes the kurtosis (Fisher or Pearson) of a dataset.

Kurtosis is the fourth central moment divided by the square of the variance. If Fisher’s definition is used, then 3.0 is subtracted from the result to give 0.0 for a normal distribution.

If bias is False then the kurtosis is calculated using k statistics to eliminate bias coming from biased moment estimators

Setting fisher to False will give you what you expected:

In [1]: a = np.array([   1. ,    2. ,    2.5,  400. ,    6. ,    0. ])

In [2]: scipy.stats.kurtosis(a, fisher=False)
Out[2]: 4.198860780044809

Upvotes: 9

Related Questions