You are here

private static function PHPExcel_Calculation_Statistical::_inverse_ncdf3 in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php \PHPExcel_Calculation_Statistical::_inverse_ncdf3()

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php, line 586

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

private static function _inverse_ncdf3($p) {

  //	ALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3.
  //	Produces the normal deviate Z corresponding to a given lower
  //	tail area of P; Z is accurate to about 1 part in 10**16.
  //
  //	This is a PHP version of the original FORTRAN code that can
  //	be found at http://lib.stat.cmu.edu/apstat/
  $split1 = 0.425;
  $split2 = 5;
  $const1 = 0.180625;
  $const2 = 1.6;

  //	coefficients for p close to 0.5
  $a0 = 3.3871328727963665;
  $a1 = 133.14166789178438;
  $a2 = 1971.5909503065513;
  $a3 = 13731.69376550946;
  $a4 = 45921.95393154987;
  $a5 = 67265.77092700871;
  $a6 = 33430.57558358813;
  $a7 = 2509.0809287301227;
  $b1 = 42.31333070160091;
  $b2 = 687.1870074920579;
  $b3 = 5394.196021424751;
  $b4 = 21213.794301586597;
  $b5 = 39307.89580009271;
  $b6 = 28729.085735721943;
  $b7 = 5226.495278852854;

  //	coefficients for p not close to 0, 0.5 or 1.
  $c0 = 1.4234371107496835;
  $c1 = 4.630337846156546;
  $c2 = 5.769497221460691;
  $c3 = 3.6478483247632045;
  $c4 = 1.2704582524523684;
  $c5 = 0.2417807251774506;
  $c6 = 0.022723844989269184;
  $c7 = 0.0007745450142783414;
  $d1 = 2.053191626637759;
  $d2 = 1.6763848301838038;
  $d3 = 0.6897673349851;
  $d4 = 0.14810397642748008;
  $d5 = 0.015198666563616457;
  $d6 = 0.0005475938084995345;
  $d7 = 1.0507500716444169E-9;

  //	coefficients for p near 0 or 1.
  $e0 = 6.657904643501103;
  $e1 = 5.463784911164114;
  $e2 = 1.7848265399172913;
  $e3 = 0.29656057182850487;
  $e4 = 0.026532189526576124;
  $e5 = 0.0012426609473880784;
  $e6 = 2.7115555687434876E-5;
  $e7 = 2.0103343992922881E-7;
  $f1 = 0.599832206555888;
  $f2 = 0.1369298809227358;
  $f3 = 0.014875361290850615;
  $f4 = 0.0007868691311456133;
  $f5 = 1.8463183175100548E-5;
  $f6 = 1.421511758316446E-7;
  $f7 = 2.0442631033899397E-15;
  $q = $p - 0.5;

  //	computation for p close to 0.5
  if (abs($q) <= split1) {
    $R = $const1 - $q * $q;
    $z = $q * ((((((($a7 * $R + $a6) * $R + $a5) * $R + $a4) * $R + $a3) * $R + $a2) * $R + $a1) * $R + $a0) / ((((((($b7 * $R + $b6) * $R + $b5) * $R + $b4) * $R + $b3) * $R + $b2) * $R + $b1) * $R + 1);
  }
  else {
    if ($q < 0) {
      $R = $p;
    }
    else {
      $R = 1 - $p;
    }
    $R = pow(-log($R), 2);

    //	computation for p not close to 0, 0.5 or 1.
    if ($R <= $split2) {
      $R = $R - $const2;
      $z = ((((((($c7 * $R + $c6) * $R + $c5) * $R + $c4) * $R + $c3) * $R + $c2) * $R + $c1) * $R + $c0) / ((((((($d7 * $R + $d6) * $R + $d5) * $R + $d4) * $R + $d3) * $R + $d2) * $R + $d1) * $R + 1);
    }
    else {

      //	computation for p near 0 or 1.
      $R = $R - $split2;
      $z = ((((((($e7 * $R + $e6) * $R + $e5) * $R + $e4) * $R + $e3) * $R + $e2) * $R + $e1) * $R + $e0) / ((((((($f7 * $R + $f6) * $R + $f5) * $R + $f4) * $R + $f3) * $R + $f2) * $R + $f1) * $R + 1);
    }
    if ($q < 0) {
      $z = -$z;
    }
  }
  return $z;
}