I need to calculate a P-value (for significance checking) out of the Z value, mean(0), standarddeviation(1), normal distrubution being cummulative.
Is there a function in PHP that could do that?
This is my current code:
$P_value = (1/sqrt(2*pi()))*exp(-0.5*pow($this->ZValue,2));
ZValue = -4,688072309 which is confirmed the right value.
Expected value: 1,37895E-06
Value: 6.9681241978373E-6
Probably something wrong in the formula, but can't spot the fault.
Edit:
If anyone is interested, here is the code that does work:
function CalculateP_Value(){
$this->CalculateZ();
$this->PValue = (1/sqrt(2*pi()))*exp(-0.5*pow($this->ZValue,2));
}
function SetConstant(){
$this->CalculateZ();
$this->A1 = 0.319381530;
$this->A2 = -0.356563782;
$this->A3 = 1.781477937;
$this->A4 = -1.8221255978;
$this->A5 = 1.330274429;
if($this->ZValue>0){
$this->K = 1.0/(1.0+0.2316419*$this->ZValue);
}
else{
$this->ZValue*=-1;
$this->K = 1.0/(1.0+0.2316419*$this->ZValue);
}
}
function CalculateCumulative(){
$this-> SetConstant();
$this-> CalculateP_Value();
$this->Cumulative = $this->GetCalculateCumulative($this->ZValue);
}
function GetCalculateCumulative($z) {
if($z >= 0) {
$val = 1.0 - $this->PValue*($this->A1*$this->K + $this->A2*pow($this->K,2) + $this->A3*pow($this->K,3) + $this->A4*pow($this->K,4) + $this->A5*pow($this->K,5));
return $val;
}
else {
$val = 1.0 - $this->GetCalculateCumulative(-1 * $z);
return $val;
}
}