Content deleted Content added
→Merge discussion: struck out indications of blindness |
→Kurtosis algorithm biased for normal distribution?: new section |
||
Line 425:
For this article as old speedup calculation method is at [[assumed mean]]. [[User:Dmcq|Dmcq]] ([[User talk:Dmcq|talk]]) 09:19, 17 May 2013 (UTC)
== Kurtosis algorithm biased for normal distribution? ==
[[Kurtosis|The wikipedia page for kurtosis]] claims that unbiased estimation of kurtosis is possible for normally distributed inputs. However, when I run the code my results are clearly biased.
<code>
[hs4 ~] 30$ ~/tmp/simple_kurt.py
Average kurtosis: -0.545012387836
[hs4 ~] 30$ ~/tmp/simple_kurt.py
Average kurtosis: -0.536851508033
[hs4 ~] 30$ ~/tmp/simple_kurt.py
Average kurtosis: -0.55578863384
[hs4 ~] 30$ ~/tmp/simple_kurt.py
Average kurtosis: -0.546190322949
</code>
Here's the code I'm running:
<syntaxhighlight lang="python">
#!/usr/bin/python2.7
from __future__ import division
from random import gauss
def kurtosis(data):
n = 0
mean = 0
M2 = 0
M3 = 0
M4 = 0
for x in data:
n1 = n
n = n + 1
delta = x - mean
delta_n = delta / n
delta_n2 = delta_n * delta_n
term1 = delta * delta_n * n1
mean = mean + delta_n
M4 = M4 + term1 * delta_n2 * (n*n - 3*n + 3) + 6 * delta_n2 * M2 - 4 * delta_n * M3
M3 = M3 + term1 * delta_n * (n - 2) - 3 * delta_n * M2
M2 = M2 + term1
kurtosis = (n*M4) / (M2*M2) - 3
return kurtosis
max_datasets = 10000
sum_kurtosis = 0
for lv in range(max_datasets):
data = [gauss(0, 1) for i in range(10)]
sum_kurtosis += kurtosis(data)
print "Average kurtosis:", sum_kurtosis/max_datasets
</syntaxhighlight>
[[Special:Contributions/208.77.214.129|208.77.214.129]] ([[User talk:208.77.214.129|talk]]) 21:02, 3 June 2013 (UTC)
|