简体   繁体   中英

Z-score to percentile in PHP

I need a z-score to percentile calculator in PHP. Is there a simple formula suitable to PHP or an already written function. What should I use?

Simplest way is aboulang2002 at yahoo dot com's contribute on PHP manual:

<?
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";
?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM