// Function to calculate square of value - mean
function sd_square($x, $mean) { return pow($x - $mean,2); }
// Function to calculate standard deviation (uses sd_square)
function sd($array)
{
if(count($array)> 0):
return sqrt(
array_sum(array_map("sd_square",
$array,
array_fill
(
0,
count($array),
(array_sum($array) / count($array))
)
)
) / (count($array)-1) );
endif;
}
No comments:
Post a Comment