Inconsistent Skewness Results Between Basic Skewness Formula, Python And R
Solution 1:
I don't have access to the packages you mention right now so I can't check which formula they apply, however, you seem to be using Pearson's second skewness coefficient (see wikipedia). The estimator for the sample skewness is given on the same page and is given by the third moment which can be calculated simply by:
> S <- mean((data-mean(data))^3)/sd(data)^3> S
[1] 0.2984792
> n <- length(data)> S_alt <- S*n^2/((n-1)*(n-2))> S_alt
[1] 0.3076471
See the alternative definition on the wiki page which yields the same results as in your example.
Solution 2:
The skewness is generally defined as the third central moment (at least when it is being used by statisticians.) The Wikipedia skewness page explains why the definition you found is unreliable. (I had never seen that definition.) The code in descdist
is easy to review:
moment <- function(data, k) {
m1 <- mean(data) # so thisis a "central moment"return(sum((data - m1)^k)/length(data))
}
skewness <- function(data) {
sd <- sqrt(moment(data, 2))
return(moment(data, 3)/sd^3)}
skewness(data)
#[1] 0.3030131
The version you use is apparently called 'median skewness' or 'non-parametric skewness'. See: https://stats.stackexchange.com/questions/159098/taming-of-the-skew-why-are-there-so-many-skew-functions
Post a Comment for "Inconsistent Skewness Results Between Basic Skewness Formula, Python And R"