[R] Computing skewness and kurtosis with the moments package
Ben Bolker
bolker at zoo.ufl.edu
Fri Sep 8 22:24:45 CEST 2006
Roger Leigh <rleigh <at> whinlatter.ukfsn.org> writes:
>
> With SPSS, I get
> Skewness -0.320
> Kurtosis -1.138
>
> With R:
> > skewness(loglen)
> [1] -0.317923
> > kurtosis(loglen)
> [1] 1.860847
>
> Using the example skew and kurtosis functions from M. J. Crawley's
> "Statistics: An introduction using R": pp 69 and 72:
>
> > mskew(loglen)
> [1] -0.3158337
> > mkurtosis(loglen)
> [1] -1.155441
>
There are two differences between the R functions;
(1) Crawley subtracts 3 from E[x^4]/E[x^2]^2, the
kurtosis function in the moments package doesn't.
(2) Crawley uses var(x), which is sum((x-mean(x))^2)/(n-1),
rather than sum((x-mean(x))^2)/n [I'm not sure I got all
the parentheses in the right place.]
With these differences corrected the two sets of functions
give the same answers.
They still don't give exactly the same answers as SPSS, but ...
I wouldn't worry about it too much since the uncertainties in
the skew and kurtosis are likely to be much larger.
from _Numerical Recipes_:
if the difference between n and n−1 ever matters to you, then you are probably
up to no good anyway - e.g., trying to substantiate a questionable hypothesis
with marginal data.
cheers
Ben Bolker
More information about the R-help
mailing list