【问题标题】:PHP Two Tailed Z-Score to P (Probability) CalculatorPHP 两尾 Z 分数到 P(概率)计算器
【发布时间】:2013-12-26 03:50:23
【问题描述】:

我一直在搜索,找不到任何关于此的内容。

我正在寻找一个使用双尾表将 Z 分数转换为概率的函数,最好是在 PHP 中。 (比如这个:http://www.sjsu.edu/faculty/gerstman/StatPrimer/z-two-tails.pdf

我唯一的其他选择是根据该表制作一个数组并比较 Z-Score.. 一定有更好的方法。

编辑:

下面是 PHP.net 统计功能页面上的一段代码。这些功能的文档记录确实很差。 下面的函数将准确地将单尾 z 分数计算为概率。

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;
    }
}

【问题讨论】:

    标签: php statistics formula


    【解决方案1】:

    找到解决办法:

    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)
    {
             return (1 - erf($n / sqrt(2)))/2;
             //I removed the $n < 0 test which inverses the +1/-1
    }
    
    function cdf_2tail($n)
    {
            return 2*cdf($n);
                //After a little more digging around, the two tail test is simply 2 x the cdf.
    }
    

    我根据http://vassarstats.net/tabs.html#z 和 z-score 表测试了我的结果。

    正确到0.1%

    【讨论】:

      猜你喜欢
      • 2021-06-30
      • 2011-09-30
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多