note 66447 deleted from function.stats-standard-deviation by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Aug 2009 00:15:44 +0000 |
| Subject: | note 66447 deleted from function.stats-standard-deviation by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159963@lists.php.net to get a copy of this message | ||
Note Submitter: mightymrj at hotmail dot com
----
Here's a couple functions I made that easily calculate the standard deviation.
function average($array){
$sum = array_sum($array);
$count = count($array);
return $sum/$count;
}
//The average function can be use independantly but the deviation function uses the average
function.
function deviation ($array){
$avg = average($array);
foreach ($array as $value) {
$variance[] = pow($value-$avg, 2);
}
$deviation = sqrt(average($variance));
return $deviation;
}
I hope this is useful