php - 在 PHP 中创建 P 值

标签 php statistics

我需要根据 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;
    }
}

最佳答案

我进一步研究了它,似乎从 z 分数计算 p 值并不是那么容易。 This gives a formula ,这似乎是一个级数计算。您的公式看起来很接近它,但奇怪的是它给出的值比预期的要大。如果有的话,它应该比预期的要小。

至于解决方案,我认为最好只使用转换表,因为您要处理标准分布和设定的显着性水平(或几个)。

关于php - 在 PHP 中创建 P 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22150348/

相关文章:

python - 检验零假设回归系数等于 statsmodels OLS 中的非零值

python - 在 Statsmodels RegressionResults 中调用对数似然?

php - 将一段javascript代码转换成php

php - 干净的 URL - 我该如何实现这一点?

php - 使用 PhP 连接到 HTML 的 MySQL 表

sql - 关联 varchar 值

python - 如果变量包含的只是数字,如何知道变量是分类变量还是数值变量?

javascript - 通过ajax数据传递循环数据

php - 错误异常 : Creating default object from empty value

python - 在python中计算狄利克雷分布的pdf