我需要PHP中的z-score到percentile计算器。是否有适合PHP或已编写函数的简单公式。我该怎么用?
答案 0 :(得分:5)
最简单的方法是aboulang2002在yahoo dot com上对PHP手册的贡献:
<?
function erf($x)
{
$pi = 3.1415927;
$a = (8*($pi - 3))/(3*$pi*(4 - $pi));
$x2 = $x * $x;
$ax2 = $a * $x2;
$num = (4/$pi) + $ax2;
$denom = 1 + $ax2;
$inner = (-$x2)*$num/$denom;
$erf2 = 1 - exp($inner);
return sqrt($erf2);
}
function cdf($n)
{
if($n < 0)
{
return (1 - erf($n / sqrt(2)))/2;
}
else
{
return (1 + erf($n / sqrt(2)))/2;
}
}
$zscore = MYZSCORE;
print 'Percentile: ' . cdf($zscore) * 100 . "\n";
?>