Posted by NC on 10/05/06 18:31
Jeff Gardner wrote:
>
> Does anyone have more details on stats_standard_deviation
> than the manual provides?
Why bother? Standard deviation is a really simple thing to
compute:
function stat_mean ($data) {
return (array_sum($data) / count($data));
}
function stat_var ($data) {
$n = count ($data);
$mean = stat_mean ($data);
$sum = 0;
foreach ($data as $element) {
$sum += pow (($element - $mean), 2);
}
return ($sum / ($n - 1));
}
function stat_stdev ($data) {
return sqrt (stat_var($data));
}
Cheers,
NC
[Back to original message]
|