Moments, Skewness and Kurtosis (Statistics in Erlang part 8)
August 27, 2008 Erlang, Math, Programming, Statistics, Tools and Libraries, Tutorials No Comments[digg-reddit-me]So, it was pointed out to me that I had the central moments, but not the moments – ie, the ones not normalized against the input’s average. Also, it was pointed out that most people don’t know that kurtosis and skewness are related to the central moments. Furthermore, it turns out (and I didn’t know this) that there are in fact meaningful uses of floating-point exponents in moments.
So, I implemented moments, I replaced my central moments implementation, and I gave name wrappers for skewness and kurtosis to make them easier to identify.
This closes issues 169, 170, 171, 172 and 173. As usual, this code is part of the ScUtil library, which is free and MIT licensed, because the GPL is evil.
moment(List, N) when is_list(List), is_number(N) ->
scutil:arithmetic_mean( [ pow(Item, N) || Item <- List ] ).
moments(List) ->
moments(List, [2,3,4]).
moments(List, Moments) when is_list(Moments) ->
[ moment(List, M) || M <- Moments ].
central_moment(List, N) when is_list(List), is_number(N) ->
ListAMean = scutil:arithmetic_mean(List),
scutil:arithmetic_mean( [ pow(Item-ListAMean, N) || Item <- List ] ).
central_moments(List) ->
central_moments(List, [2,3,4]).
central_moments(List, Moments) when is_list(Moments) ->
[ central_moment(List, M) || M <- Moments ].
skewness(List) -> central_moment(List, 3).
kurtosis(List) -> central_moment(List, 4).
