开发者

How to generate a Cumulative Normal Distribution in PHP [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

Can anyone tell me how to get the equivalent of the Excel (NORMDIST (TRUE)) 开发者_运维知识库function in PHP?

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).

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

Any help gratefully appreciated!


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

http://abtester.com/calculator/

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜