473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

stats_standard_deviation

Does anyone have more details on stats_standard_deviation than the
manual provides?
--

Regards,

Jeff Gardner
___________________________

"Contrary to popular belief, Unix is user friendly. It just happens
to be very selective about who its friends are." --Kyle Hearn
Oct 4 '06 #1
2 3899
Jeff Gardner wrote:
Does anyone have more details on stats_standard_deviation than the
manual provides?
Hi Jeff,

The describtion is very bad indeed.

Why use an undocumented (bad documented) function for such a simple thing?
I would write my own implementation in such case.
Calculation the SD is very straightforward.

On the same page on www.php.net you can also find a contribution with a
working example.

[Source]
http://nl2.php.net/manual/en/functio...-deviation.php

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;
}

Regards,
Erwin Moller

Oct 5 '06 #2
NC
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

Oct 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.