CDF – Cumulative Distribution Function in PHP

function getPRScore($mean, $sd, $x){

    $z = ($x-$mean)/sqrt(2*$sd*$sd);
    $t = 1/(1+0.3275911*abs($z));
    $a1 =  0.254829592;
    $a2 = -0.284496736;
    $a3 =  1.421413741;
    $a4 = -1.453152027;
    $a5 =  1.061405429;
    $erf = 1-((((($a5*$t + $a4)*$t) + $a3)*$t + $a2)*$t + $a1)*$t*exp(-$z*$z);
    $sign = 1;
    if($z < 0){
      $sign = -1;
    }
    
//累加分配乘上100等於PR值
$pr=(1/2)*(1+$sign*$erf)*100; 
 
//PR值校正, 四捨五入取整數, PR介於1~99之間
$pr= round($pr, 0); 
if($pr<=1)$pr=1;
if($pr>=99)$pr=99;       
 
return $pr;
}
echo getPRScore(50, 10, 60);

6 thoughts on “CDF – Cumulative Distribution Function in PHP

  1. Mike Webster jersey

    throughout LANOne a period of time judging by going to be the way,for those times when I was learning how to deal with have to some coding gymnastics, I rent it out going to be the website I was working everywhere over the

  2. gary

    Hello very cool web site!! Guy .. Excellent .
    . Wonderful .. I’ll bookmark your web site and take the feeds also? I’m
    happy to search out a lot of useful info here in the post,
    we need work out more strategies in this regard, thanks for sharing.

    . . . . .

Comments are closed.