How to generate a Cumulative Normal Distribution in PHP [closed]
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 ));
}
}
精彩评论