= 1.0) $h[11]++; else $h[ceil($r[$i] * 10)]++; } foreach ($h as $h_item) $h_sum += $h_item; // adjust one of the $h values if necessary to ensure $h_sum = $sample_size $adj = $sample_size - $h_sum; if ($adj != 0) { for ($i = 0; $i <= 11; $i++) { $h[$i] += $adj; if ($h[$i] >= 0) break; $h[$i] -= $adj; } } $mean = $sum / $sample_size; $sum = 0.0; // Now calculate their standard deviation foreach ($r as $r_item) $sum += pow($r_item - $mean, 2); $sd = sqrt($sum / $sample_size); // Draw a histogram of the data with interval 0.1 // If sample size > 300 then normalize histogram to 300 $scale = 1.0; if ($sample_size > 300) $scale = 300.0 / $sample_size; echo 'Sample size '.$sample_size.PHP_EOL; echo ' Mean '. str_pad(number_format($mean, 6, '.', ''), 8, ' ', STR_PAD_LEFT). ' SD '. str_pad(number_format($sd, 6, '.', ''), 8, ' ', STR_PAD_LEFT).PHP_EOL; $i = -1; foreach ($h as $h_item) { if ($i == -1) echo '< 0.00 : '; else if ($i == 10) echo '>=1.00 : '; else echo ' '. str_pad(number_format($i / 10.0, 2, '.', ''), 4, ' ', STR_PAD_LEFT). ' : '; echo str_pad($h_item, 5, ' ', STR_PAD_LEFT).' '. str_repeat('*', round($h_item * $scale)).PHP_EOL; $i++; } } ?>