Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
i wrote a function to compute standard deviation because i am in the ridiculous and unenviable position of using a networked version of perl with a non functioning ppm
(else i would have used Math::StdDev)
now it turns out my function doesn't give the same results as Excel or SPSS (its not because one is the sample stddev and the other the population stddev i already checked that)
next i copied a stddev function straight out of a linux journal article on benchmarking
http://www.linuxjournal.com/article/6540
sub std_dev_ref_sum { my $ar = shift; my $elements = scalar @$ar; my $sum = 0; my $sumsq = 0; foreach (@$ar) { $sum += $_; $sumsq += ($_ **2); } return sqrt( $sumsq/$elements - (($sum/$elements) ** 2)); }
this gives the same answers as my original code (hence i don't bother posting my original code as well)
does anyone know why i might be getting different results to these commercially available applications?
20050722 Janitored by Corion: Added formatting, linkified link