What does the forumla Σ(x-xbar)/((n-1)v^(3/2)) calculate?

tuna

New Member
#7
Precisely what type of skewness does it measure? I was especially wondering if there was a Mathematica function to calculate this. Thanks
 

Dragan

Super Moderator
#8
Precisely what type of skewness does it measure? I was especially wondering if there was a Mathematica function to calculate this. Thanks

If you're using Mathematica version 7.0 then use:


Code:
In[8]:= data = {2., 4, 3, 7, 8, 10, 12, 6, 17};
x = Skewness[data]


Out[9]= 0.695634
 

tuna

New Member
#9
But the Mma Skewness[] function and the formula I gave:



give different values. For example, using the 2 following functions to return the list {variance, skewness} with 2 different methods, I get 2 different answers for the skewness:

In:
|fn6[x_] := Module[{xbar, n, v},
| n = Length[x];
| {v = If[n == 1, 0,
| xbar = Apply[Plus, x]/n;
| Apply[Plus, (x - xbar)^2]/(n - 1)
| ],
| If[v == 0, Indeterminate,
| Apply[Plus, (x - xbar)^3]/((n - 1)*v^(3/2))
| ]
| }
| ];
|
|fn7[x_] := {Variance[x], Skewness[x]}
|
|N[fn6[Range[20]^2]]
|N[fn7[Range[20]^2]]

Out:
|{16359., 0.592322}
|{16359., 0.60771}

What's the problem?

Thanks
 

Dragan

Super Moderator
#10
What's the problem?

Thanks
Easy to answer.

Mathematica is doing this (slightly different)

Code:
data = {2., 4, 3, 7, 8, 10, 12, 6, 17};
m = Mean[data];
m2 = Mean[(data - m)^2];
m3 = Mean[(data - m)^3];
s = Sqrt[m2];

skew = m3/s^3


The method that Mathematica is using (and your formula) is based on Method of Moments.

On the other hand, if you consider using SAS, SPSS, or Minitab, the calculation is based on Fisher's k-statistics.

More specifically, suppose we have a set N data points that we standardize to Z-scores (Z).

Then, the skewness is computed as:

[N^2 / ( N (N-1) (N-2) ) ] * Z^3

Most commercial software packages, today, compute skewness (kurtosis) based on Fisher's k-statistics and not based on the method of moments (i.e. what Mathematica does and the formula you suggested).
 

Dragan

Super Moderator
#12
Thanks. So is my Mma function for skewness (based on the method of moments) the most efficient way to have coded it?

I think you should use values of skewness (kurtosis) that people are used to now days.

Here's my Mma function that computes the third (skewness), fourth (kurtosis), fifth, and sixth standardized cumulants. The values you will obtain for skew and kurtosis are the same as you get using SAS, SPSS, SPLUS, Minitab,...etc.

Code:
EmpiricalCumulantsK[data_List] := 
 Module[{stdata, n, s2, s3, s4, s5, s6, gamma3, gamma4, gamma5, 
   gamma6, cumulants},

  stdata = (data - Mean[data])/StandardDeviation[data];
  n = Length[data];
  s2 = n - 1;
  s3 = Total[stdata^3];
  s4 = Total[stdata^4];
  s5 = Total[stdata^5];
  s6 = Total[stdata^6];

  Print[ "Standardized third, fourth, fifth, and sixth cumulants \
based on Fisher's k-statistics."];

  gamma3 = 1/(n*(n - 1)*(n - 2))*(n^2*s3);
  
gamma4 = 
   1/(n*(n - 1)*(n - 2)*(n - 3))*( (n^3 + n^2)*s4 - 
      3*(n^2 - n)* s2^2 );
 
 gamma5 = 
   1/(n*(n - 1)*(n - 2)*(n - 3)*(n - 4))* ((n^4 + 5*n^3)*s5 - 
      10*(n^3 - n^2)* s3*s2 );
 
 gamma6 = 
   1/(n*(n - 1)*(n - 2)*(n - 3)*(n - 4)*(n - 
        5))*( ( n^5 + 16*n^4 + 11*n^3 - 4*n^2)*s6 - 
       15*n*(n - 1)^2*(n + 4)*s4*s2 - 
       10*(n^4 - 2*n^3 + 5*n^2 - 4*n)* s3^2 + 
       30*(n^3 - 3*n^2 + 2*n)*s2^3 ) ;

  cumulants = {gamma3, gamma4, gamma5, gamma6}  ]