Difference between third moment, skewness and E(x^3)

6 views (last 30 days)
Can someone please explain why there is such a difference between skewness, the third moment and E(x^3), as in the following code:
mu = 0;
sigma = 1;
skew = 3;
kurt = 15;
r = pearsrnd(mu, sigma, skew, kurt, 10000, 1);
moment(r,3)
skewness(r)
mean(r.^3)
I know that the moment function computes a central moment, which is why I set mu to zero. Similarly skewness computes a standardized moment, which is why I set sigma to one. Under these circumstances, they should be the same, no?
The difference between the third moment and the expectation of the r cubed is acceptable, but the skewness varies much more, in some cases considerably.
  1 Comment
Fergus Fettes
Fergus Fettes on 28 Mar 2017
(and perhaps I should mention, you get the same pattern with moment(r,4) kurtosis(r) and mean(r.^4), presumably for the same reasons)

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 28 Mar 2017
Edited: the cyclist on 28 Mar 2017
The output is within expected sample error of these statistics (assuming you are seeing roughly the same output as I am).
This is explicitly noted in the documentation for pearsrnd:
" Note: Because r is a random sample, its sample moments, especially the skewness and kurtosis, typically differ somewhat from the specified distribution moments. pearsrnd uses the definition of kurtosis for which a normal distribution has a kurtosis of 3. Some definitions of kurtosis subtract 3, so that a normal distribution has a kurtosis of 0. The pearsrnd function does not use this convention."
Try cranking up your number of trials, and you'll see that they converge:
mu = 0;
sigma = 1;
skew = 3;
kurt = 15;
rng 'default'
NT = 10000000;
r = pearsrnd(mu, sigma, skew, kurt, NT, 1);
moment(r,3)
skewness(r)
mean(r.^3)
gives output
ans =
3.0077
ans =
3.0047
ans =
3.0075
  3 Comments
Fergus Fettes
Fergus Fettes on 29 Mar 2017
Edited: Fergus Fettes on 29 Mar 2017
You were obviously on the right track, but I don't think you really answered the question. The sample error explains why the results will be different across different iterations, but more details are needed to understand why it is different between the different functions.
Ah what the hell, I'll accept your answer anyway :).
Re John, the kurtosis function doesn't subtract three, fyi.
the cyclist
the cyclist on 29 Mar 2017
Actually, I think the answer you provided to your own question is better than mine. I suggest you unaccept mine and accept your own.
There are a fair number of questions on this forum where people don't understand that a sample will not always have the exact moments as the inputs. But your question was actually a little more subtle, and your answer is more thorough.

Sign in to comment.

More Answers (1)

Fergus Fettes
Fergus Fettes on 29 Mar 2017
After digging around in the code for the three functions, I found the following;
  • Moment calculates the mean of the vector (r), then subtracts this from r-- this centers the values. It then takes this new vector to the power of the moment (the third power for skewness), and takes the mean.
meanx = mean(x,dim);
sigma = mean((x - repmat(meanx, tile)).^order,dim);
  • So the reason for the discrepancy between moment(r,3) and mean(r.^3) is that the mean of the vector r is not exactly equal to zero-- as the cyclist mentioned, this error comes from the expected error of pearsrnd. This means that the centering actually does something, and when mean does no centering it is actually slightly off.
  • Skewness does something similar:
x0 = x - repmat(nanmean(x,dim), tile);
s2 = nanmean(x0.^2,dim);
m3 = nanmean(x0.^3,dim);
  • Because the skewness calculates the sigma, and the sigma produced by pearsrnd is not exactly one as I set it, when you correct for the sigma you get a different value than when you don't.
So the cyclist was basically right. The fact that I set mu to zero and sigma to one was undone by the statistical nature of the distribution.
And the three values are therefore as follows:
  1. mean(x.^n) returns the nth RAW moment of a vector x
  2. moment(x,n) returns the nth CENTRAL moment of vector x
  3. skewness(x) and kurtosis(x) return the 3rd and 4th STANDARDIZED moments of vector x
  1 Comment
Daniel Schiller
Daniel Schiller on 19 Sep 2019
Thank you for that "code digging" research. It took me some hours today to understand what was going on with my data ... and now your anwers explained it to me.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!