Tuesday 24 July 2012

Calculating the Standard Deviation using PHP

// Calculating the Standard Deviation.
private function standard_deviation($aValues, $bSample = false)
{
 $fMean = array_sum($aValues) / count($aValues);
 $fVariance = 0.0;
 foreach ($aValues as $i)
 {
  $fVariance += pow($i - $fMean, 2);
 }
 $fVariance /= ( $bSample ? count($aValues) - 1 : count($aValues) );
 return (float) sqrt($fVariance);
}

No comments:

Post a Comment

Please post any queries and comments here.