Scripts

Standaard Deviatie (STDEV)

Deze functie berekend de Standaard Deviatie van een reeks getallen uit een Array. Hij functioneerd exact hetzelfde als de STDEV functie van Microsoft Excel. $a is de array welke elke getallenreeks kan bevatten. Bijv: $a = array(2, 3, 5, 2, 10, 0, 10, 10, 0, 10, 0, 0); $STDEV = standard_deviation ($a); echo $STDEV; // uitkomst 4,438126823 Bron: http://www.ajdesigner.com/php_code_statistics/standard_deviation_sample.php Uitleg: http://nl.wikipedia.org/wiki/Standaard_deviatie

standaard-deviatie-stdev
<?PHP

function standard_deviation ($a)
				{
				  //variable and initializations
				  $the_standard_deviation = 0.0;
				  $the_variance = 0.0;
				  $the_mean = 0.0;
				  $the_array_sum = array_sum($a); //sum the elements
				  $number_elements = count($a); //count the number of elements
				
				  //calculate the mean
				  $the_mean = $the_array_sum / $number_elements;
				
				  //calculate the variance
				  for ($i = 0; $i < $number_elements; $i++)
				  {
					//sum the array
					$the_variance = $the_variance + ($a[$i] - $the_mean) * ($a[$i] - $the_mean);
				  }
				
				  $the_variance = $the_variance / ($number_elements - 1.0);
				
				  //calculate the standard deviation
				  $the_standard_deviation = pow( $the_variance, 0.5);
				
				  //return the variance
				  return $the_standard_deviation;
				}


$a = array(2, 3, 5, 2, 10, 0, 10, 10, 0, 10, 0, 0);
$STDEV =  standard_deviation ($a);
echo $STDEV;  // uitkomst 4,438126823

?>

Reacties

0
Nog geen reacties.