Skip to content

Commit

Permalink
Merge pull request #583 from poke1024/skewness
Browse files Browse the repository at this point in the history
CentralMoment[], Skewness[], Kurtosis[]
  • Loading branch information
sn6uv committed Sep 25, 2016
2 parents 6d9c95b + 77ab14c commit a7092b2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions mathics/builtin/lists.py
Expand Up @@ -3080,6 +3080,55 @@ def apply(self, expr, levels, evaluation):
return Reverse._reverse(expr, 1, py_levels)


class CentralMoment(Builtin): # see https://en.wikipedia.org/wiki/Central_moment
'''
<dl>
<dt>'CentralMoment[$list$, $r$]'
<dd>gives the the $r$th central moment (i.e. the $r$th moment about the mean) of $list$.
</dl>
>> CentralMoment[{1.1, 1.2, 1.4, 2.1, 2.4}, 4]
= 0.100845
'''

rules = {
'CentralMoment[list_List, r_]': 'Total[(list - Mean[list]) ^ r] / Length[list]',
}


class Skewness(Builtin): # see https://en.wikipedia.org/wiki/Skewness
'''
<dl>
<dt>'Skewness[$list$]'
<dd>gives Pearson's moment coefficient of skewness for $list$ (a measure for estimating
the symmetry of a distribution).
</dl>
>> Skewness[{1.1, 1.2, 1.4, 2.1, 2.4}]
= 0.407041
'''

rules = {
'Skewness[list_List]': 'CentralMoment[list, 3] / (CentralMoment[list, 2] ^ (3 / 2))',
}


class Kurtosis(Builtin): # see https://en.wikipedia.org/wiki/Kurtosis
'''
<dl>
<dt>'Kurtosis[$list$]'
<dd>gives the Pearson measure of kurtosis for $list$ (a measure of existing outliers).
</dl>
>> Kurtosis[{1.1, 1.2, 1.4, 2.1, 2.4}]
= 1.42098
'''

rules = {
'Kurtosis[list_List]': 'CentralMoment[list, 4] / (CentralMoment[list, 2] ^ 2)',
}


class Mean(Builtin):
"""
<dl>
Expand Down

0 comments on commit a7092b2

Please sign in to comment.