The formulas for skewness and kurtosis are as follows:
As we can see, the formulas are nearly identical. Each requires n, the number of data points. In addition, each requires the average or mean of those data points (the X with the bar over it). Finally, each requires the standard deviation of the data points, S.
To implement these formulas, we start with the Kn measure. Kn is the count of the number of data points in our data table, R07_Table. This is n in our formulas for skewness and kurtosis.
Next, we calculate the Kmean measure. To calculate Kmean, we simply use AVERAGEX to return the average of the Values column in the R07_Table table.
We also need the sample standard deviation of our data points, KStdDev. To calculate KStdDev, we simply use the STDEVX.S function to calculate the standard deviation of the Values column in the R07_Table table.
Now that we have the base measures for our formulas, we can now calculate our Skewness and Kurtosis measures. We start our Skewness measure by simply setting the __Mean, __StdDev, and __n variables equal to the Kmean, KStdDev, and Kn measures, respectively. Since we must calculate the sum of the cube of the differences between each row's Value column and the mean of the Value column, we create the table variable, __Table, and use our base data table, R07_Table, as a starting point. We use ADDCOLUMNS to add the __Skew column to our table and simply implement the summation portion of the formula for skewness. We can now implement the rest of the formula for skewness by dividing the sum of our __Skew column by the __StdDev to the third power (cubed). We then divide this quotient by 4.
The calculation for the Kurtosis measure is identical to the calculation for the Skewness measure, except that powers of 4 are used instead of powers of 3.
We can now find our Excess Kurtosis by subtracting 3 from our Kurtosis measure. Finally, we can return the Kurtosis Type by using a SWITCH statement.