本文介绍了如何在PHP中生成累积正态分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何在PHP中获得Excel(NORMDIST(TRUE))函数的等效功能吗?

Can anyone tell me how to get the equivalent of the Excel (NORMDIST (TRUE)) function in PHP?

我尝试了PECL stats软件包(stats_dens_normal),但这似乎产生了概率质量函数(相当于在Excel中使用NORMDIST,并且累积设置为FALSE).

I have tried the PECL stats package (stats_dens_normal) but this appears to produce the probability mass function (equivalent to using NORMDIST in Excel with cumulative set to FALSE).

因此,总而言之,我想使用PHP获得与Excel的NORMDIST(x,mean,standard_dev TRUE)等效的结果.

So in summary, I want to use PHP to get the equivalent of Excel's NORMDIST(x, mean, standard_dev TRUE).

任何帮助表示感谢!

推荐答案

这里有一种用于近似累积正态分布的php方法:

There's a php method for approximate cumulative normal distribution here:

http://abtester.com/calculator/

该方法将zscore作为输入.对我来说,结果与excel的NORMDIST相似.

The method takes a zscore as input. The results for me have have been similar to excel's NORMDIST.

function cumnormdist($x)
{
  $b1 =  0.319381530;
  $b2 = -0.356563782;
  $b3 =  1.781477937;
  $b4 = -1.821255978;
  $b5 =  1.330274429;
  $p  =  0.2316419;
  $c  =  0.39894228;

  if($x >= 0.0) {
      $t = 1.0 / ( 1.0 + $p * $x );
      return (1.0 - $c * exp( -$x * $x / 2.0 ) * $t *
      ( $t *( $t * ( $t * ( $t * $b5 + $b4 ) + $b3 ) + $b2 ) + $b1 ));
  }
  else {
      $t = 1.0 / ( 1.0 - $p * $x );
      return ( $c * exp( -$x * $x / 2.0 ) * $t *
      ( $t *( $t * ( $t * ( $t * $b5 + $b4 ) + $b3 ) + $b2 ) + $b1 ));
    }
}

这篇关于如何在PHP中生成累积正态分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:26