Login  Register

messed StdDev in Array.getStatistics?

Posted by Schebique on Jun 30, 2016; 1:27pm
URL: http://imagej.273.s1.nabble.com/messed-StdDev-in-Array-getStatistics-tp5016777.html

Hello all.

I would like to know why I get a different number with custom written
functions to get standard deviation (according to
http://www.investopedia.com/terms/s/standarddeviation.asp) compare to
Array.getStatistics build-in macro function? Is there a bug or am I missing
something?

Thank you very much.
Ondrej

minimal macro:

volumeArray=newArray(3, 5, 6, 4, 4, 1, 2, 7);
volume=Mean(volumeArray);
volStDev=StDev(volumeArray);
print("custom functions send "+volume+"+-"+volStDev);
Array.getStatistics(volumeArray, min, max, volume, volStDev);
print("Array.getStatistics send "+volume+"+-"+volStDev);

//******************** functions **********************
function StDev(pole) {
    SUM=0;
    n=pole.length;
    mean=Mean(pole);
    for (x=0; x<n; x++) {
         SUM = SUM+square(pole[x]-mean);
    }
    return sqrt(SUM/n);
}

function Mean(pole) {
    mean=0;
    n=pole.length;
    for (x=0; x<n; x++) {
        mean+=pole[x];
    }
    return mean/n;
}
function square(a) {
    return a*a;
}

--
Mgr. Ondřej Šebesta
Laboratory of Confocal and Fluorescence Microscopy
Faculty of Science, Charles University in Prague
Vinicna 7
128 44 Prague
Czech Republic

Phone: +420 2 2195 1061
e-mail: [hidden email]

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html