You can calculate the Apache Java statistics in Matlab as well by importing the function. The Apache function uses an unbiased estimator of the population excess kurtosis. Excess kurtosis means substracting 3 so that the kurtosis of a normal distribution is equal to zero.
To demonstrate it I also made a Matlab function out of the function (Apache documentation):
function y = kurtosis_apache(x)
n=length(x);
mean_x = mean(x);
std_x = std(x);
y = ( (n*(n+1) / ((n -1)*(n - 2)*(n-3))) * sum((x - mean_x).^4) / std_x.^4 ) - ((3*(n-1).^2) / ((n-2)*(n-3)));
end
And my code in the command Window that shows the Matlab Apache implementation, the Java Apache implementation, and the Matlab version (biassed/unbiassed):
javaaddpath('commons-math3-3.2.jar')
import org.apache.commons.math3.stat.descriptive.moment.Kurtosis;
x = randn(1e4,1);
kurtosis_apache(x)
ans = 0.0016
kurt = Kurtosis();
kurt.evaluate(x)
ans = 0.0016
kurtosis(x)
ans = 3.0010
kurtosis(x,0)
ans = 3.0016
Note also the Matlab Kurtosis documentation:
So with the 0 flag the unbiassed Matlab implementation is exactly the same as the Apache version, when you substract 3 to make it an excess kurtosis.
(kurtosis(x,0)-3)-kurt.evaluate(x)
ans = 3.8636e-14