Comparing Matlab and Apache statistics - kurtosis -


hi comparing statistics between matlab , apache functions. here apache functions tested in java. same set of data, different results double array (double[] ) follow:

---------------------------------------            matlab       vs apache --------------------------------------- max      = 0.5451       vs 0.5450980392156862 min      = 0.4941       vs 0.49411764705882355 var      = 5.4154e-05   vs 5.415357603461868e-5 std      = 0.0074       vs 0.007358911334879547 mean     = 0.5206       vs 0.5205525290240967 kurtosis = 3.3442       vs 0.35227427833465486 skewness = 0.2643       vs 0.26466432504210746 

i checked , rechecked data, each value matlabs same used in java. here can see statistics identical, except kurtosis.

is possible kurtosis computed differently matlab , apache library? if so, data should trust then?


edit

my data subset of image matrix (containing pixels values). each subset compute above statistics. everytime, statistics match except kurtosis.

the matlab code computing kurtosis of subset following:

kurtosis( sub(:) ); // sub n x m matrix 

while 1 used in java is:

import org.apache.commons.math3.stat.descriptive.moment.kurtosis; // ... kurtosis kurt = new kurtosis(); system.out.println("-kurtosis: " + kurt.evaluate(subimg) ); 

subimg being double[n x m] array.

you can calculate apache java statistics in matlab importing function. apache function uses unbiased estimator of population excess kurtosis. excess kurtosis means substracting 3 kurtosis of normal distribution equal zero.

to demonstrate made matlab function out of 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 code in command window shows matlab apache implementation, java apache implementation, , 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 matlab kurtosis documentation:

matlab documentation

so 0 flag unbiassed matlab implementation same apache version, when substract 3 make excess kurtosis.

(kurtosis(x,0)-3)-kurt.evaluate(x) 

ans = 3.8636e-14


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -