public static function ratingAverage($positive, $total, $power = '0.05') { if ($total == 0) return 0; $z = Rating::pnormaldist(1-$power/2,0,1); //print $z; $p = 1.0 * $positive / $total; $to_sqrt = ($p*(1-$p)+$z*$z/(4*$total))/$total; if ($to_sqrt < 0) { $to_sqrt = 0.; } $sqrt = sqrt($to_sqrt); $s = ($p + $z*$z/(2*$total) - $z * $sqrt)/(1+$z*$z/$total); //print "z = $z total = $total p = $p to_sqrt = $to_sqrt s = $s"; //print '($p*(1-$p)+$z*$z/(4*$total))/$total): ' . ($p*(1-$p)+$z*$z/(4*$total))/$total . "\n"; return $s; }