【发布时间】:2014-04-04 17:06:23
【问题描述】:
我需要从 Z 值、均值 (0)、标准差 (1) 中计算 P 值(用于显着性检查),正态分布是累积的。
PHP 中有没有可以做到这一点的函数?
这是我当前的代码:
$P_value = (1/sqrt(2*pi()))*exp(-0.5*pow($this->ZValue,2));
ZValue = -4,688072309 确认正确的值。
预期值:1,37895E-06
值:6.9681241978373E-6
可能公式有问题,但无法发现错误。
编辑:
如果有人有兴趣,这里是有效的代码:
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;
}
}
【问题讨论】:
-
不。 但是你可以做一件事:找出如何根据提供的值计算 P 值 没有 PHP(算法) .然后简单地将其翻译成 PHP 代码。当您遇到困难时,请返回并在这里寻求帮助(清楚地解释问题所在、预期输出和您尝试过的代码)。
-
更新和编辑@AmalMurali
-
-0.5不应该放在括号里吗? -
@LauriK,没有什么不同,但感谢您的建议。
标签: php statistics