I am hoping to have more insight on the four types of skew from this community.
The types I refer to are mentioned in the http://www.inside-r.org/packages/cran/e1071/docs/skewness help page.
The old method was not mentioned in the help page, but I include it nonetheless.
require(moments)
require(e1071)
x=rnorm(100)
n=length(x)
hist(x)
###############type=1
e1071::skewness(x,type=1)
sqrt(n) * sum((x-mean(x))^3)/(sum((x - mean(x))^2)^(3/2)) #from e1071::skewness source
m_r=function(x,r) {n=length(x); sum((x - mean(x))^r/n);} ##from e1071::skewness help
g_1=function(x) m_r(x,3)/m_r(x,2)^(3/2)
g_1(x) ##from e1071::skewness help
moments::skewness(x) ##from e1071::skewness help
(sum((x - mean(x))^3)/n)/(sum((x - mean(x))^2)/n)^(3/2) ##from moments::skewness code, exactly as skewness help page
###############type=2
e1071::skewness(x,type=2)
e1071::skewness(x,type=1) * sqrt(n * (n - 1))/(n - 2) #from e1071::skewness source
G_1=function(x) {n=length(x); g_1(x)*sqrt(n*(n-1))/(n-2);} #from e1071::help
G_1(x)
excel.skew=function(x) { n=length(x); return(n/((n-1)*(n-2))*sum(((x-mean(x))/sd(x))^3));}
excel.skew(x)
###############type=3
e1071::skewness(x,type=3)
e1071::skewness(x,type=1) * ((1 - 1/n))^(3/2) #from e1071::skewness source
b_1=function(x) {n=length(x); g_1(x)*((n-1)/n)^(3/2); } #from e1071::skewness help page
b_1(x);
prof.skew=function(x) sum((x-mean(x))^3)/(length(x)*sd(x)^3);
prof.skew(x)
###############very old method that fails in weird cases
(3*mean(x)-median(x))/sd(x)
#I found this to fail on certain data sets as well...
Here is the paper that the author of e1071 refers to: http://onlinelibrary.wiley.com/doi/10.1111/1467-9884.00122/pdf Joanes and C. A. Gill (1998), Comparing measures of sample skewness and kurtosis.
From my reading of that paper, they suggest that type #3 has the least error.
Here are examples of the skewness from the above code:
e1071::skewness(x,type=1)
-0.1620332
e1071::skewness(x,type=2)
-0.1645113
e1071::skewness(x,type=3)
-0.1596088
#old type:
0.2694532
I also noticed that the author of e1071 wrote the skew function different from the notes in the help page. Notice the sqrt:
sqrt(n) * sum((x-mean(x))^3)/(sum((x - mean(x))^2)^(3/2)) #from e1071::skewness source
(sum((x - mean(x))^3)/n)/(sum((x - mean(x))^2)/n)^(3/2) #from moments and e1071 help page
Any ideas why the sqrt(n) is in the first equation? Which equation handles overflow/underflow better? Any other ideas why they are different (but produce the same results)?