Math_Stats
[ class tree: Math_Stats ] [ index: Math_Stats ] [ all elements ]

Source for file f_cumulative_normal_dist.php

Documentation is available at f_cumulative_normal_dist.php

  1. <?php
  2.  
  3. function normsdist$x {
  4.  
  5.     // Returns the standard normal cumulative distribution
  6.     // ---------------------------------------
  7.     
  8.     // Load tabulated values in an array
  9.     include "ndist_tabulated.php" ;
  10.     
  11.     // Discriminate upon the absolute value, then the sign of $x
  12.     $x number_format$x;
  13.     if abs$x >= 3.09 {
  14.         
  15.         $output = 0 ;
  16.             
  17.     elseif $x==0 {
  18.         
  19.         $output = 0.5 ;
  20.             
  21.     elseif $x<0 {
  22.  
  23.         // find higher boundary (next highest value with 2 decimals)
  24.         $x2 number_formatceil100*$x )/100;
  25.         $x2 = (string)$x2 ;
  26.         
  27.         // find lower boundary
  28.         $x1 number_format$x2-0.01;
  29.         $x1 = (string)$x1 ;
  30.  
  31.         // linear interpolate
  32.         $output $values[$x1$values[$x2$values[$x1)/0.01*$x $x1 ;
  33.         
  34.     else {        // if x>0
  35.     
  36.         $output = 1 - normsdist-$x ;
  37.         
  38.     }
  39.     
  40.     return number_format$output;
  41.     
  42. }
  43.  
  44.  
  45. function normsinv$y {
  46.  
  47.     // Returns the inverse standard normal cumulative distribution ( 0<y<1 )
  48.     // ---------------------------------------
  49.     
  50.     // Load tabulated values in an array
  51.     include "ndist_tabulated.php" ;
  52.     
  53.     // Discriminate upon whether $y is between 0 and 1, then upon its position relative to 0.5
  54.     $y number_format$y;
  55.     if $y<=0 || $y>=1 {
  56.     
  57.         $output = FALSE ;
  58.     
  59.     elseif $y<=0.5 {
  60.     
  61.         // find the largest index which value is smaller than $y:
  62.         
  63.         // filter array for values higher than $y
  64.         $smaller = array(;
  65.         while list$key$value each$values ) ) {
  66.             if $value <= $y {
  67.                 $smaller[$key$value ;
  68.             }
  69.         }
  70.         // order $values in decreasing terms of the $values
  71.         krsort$smallerSORT_NUMERIC ;
  72.         reset$smaller ;
  73.  
  74.         $x1 = (string)key$smaller ;
  75.         $x2 = (string)$x1+0.01 ;
  76.  
  77.         // interpolate
  78.         $output $x1 $y $values[$x1)/$values[$x2$values[$x1)*0.01 ;
  79.             
  80.     else {    // meaning $x between 0.5 and 1
  81.     
  82.         $output = - normsinv1 - $y ;
  83.         
  84.     }
  85.  
  86.     return number_format$output;
  87.  
  88. }
  89.  
  90.  
  91. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.