34        define(
'PHPEXCEL_ROOT', dirname(__FILE__) . 
'/../../');
 
   35        require(PHPEXCEL_ROOT . 
'PHPExcel/Autoloader.php');
 
   39require_once PHPEXCEL_ROOT . 
'PHPExcel/Shared/trend/trendClass.php';
 
   43define(
'LOG_GAMMA_X_MAX_VALUE', 2.55e305);
 
   46define(
'XMININ', 2.23
e-308);
 
   49define(
'EPS', 2.22
e-16);
 
   52define(
'SQRT2PI', 2.5066282746310005024157652848110452530069867406099);
 
   66                if (!is_array($array1)) { $array1 = array($array1); }
 
   67                if (!is_array($array2)) { $array2 = array($array2); }
 
   71                foreach($array1 as 
$key => $value) {
 
   72                        if ((is_bool($value)) || (is_string($value)) || (is_null($value))) {
 
   77                foreach($array2 as 
$key => $value) {
 
   78                        if ((is_bool($value)) || (is_string($value)) || (is_null($value))) {
 
   83                $array1 = array_merge($array1);
 
   84                $array2 = array_merge($array2);
 
   99        private static function _beta($p, $q) {
 
  103                        return exp(self::_logBeta($p, $q));
 
  123                } elseif (
$x >= 1.0) {
 
  128                $beta_gam = exp((0 - self::_logBeta($p, $q)) + $p * log(
$x) + $q * log(1.0 - 
$x));
 
  129                if (
$x < ($p + 1.0) / ($p + $q + 2.0)) {
 
  151                if ($p != self::$_logBetaCache_p || $q != self::$_logBetaCache_q) {
 
  152                        self::$_logBetaCache_p = $p;
 
  153                        self::$_logBetaCache_q = $q;
 
  155                                self::$_logBetaCache_result = 0.0;
 
  174                $h = 1.0 - $sum_pq * 
$x / $p_plus;
 
  185                        $d = 
$m * ($q - 
$m) * 
$x / ( ($p_minus + $m2) * ($p + $m2));
 
  197                        $d = -($p + 
$m) * ($sum_pq + 
$m) * 
$x / (($p + $m2) * ($p_plus + $m2));
 
  264                static $lg_d1 = -0.5772156649015328605195174;
 
  265                static $lg_d2 = 0.4227843350984671393993777;
 
  266                static $lg_d4 = 1.791759469228055000094023;
 
  268                static $lg_p1 = array(  4.945235359296727046734888,
 
  269                                                                201.8112620856775083915565,
 
  270                                                                2290.838373831346393026739,
 
  271                                                                11319.67205903380828685045,
 
  272                                                                28557.24635671635335736389,
 
  273                                                                38484.96228443793359990269,
 
  274                                                                26377.48787624195437963534,
 
  275                                                                7225.813979700288197698961 );
 
  276                static $lg_p2 = array(  4.974607845568932035012064,
 
  277                                                                542.4138599891070494101986,
 
  278                                                                15506.93864978364947665077,
 
  279                                                                184793.2904445632425417223,
 
  280                                                                1088204.76946882876749847,
 
  281                                                                3338152.967987029735917223,
 
  282                                                                5106661.678927352456275255,
 
  283                                                                3074109.054850539556250927 );
 
  284                static $lg_p4 = array(  14745.02166059939948905062,
 
  285                                                                2426813.369486704502836312,
 
  286                                                                121475557.4045093227939592,
 
  287                                                                2663432449.630976949898078,
 
  288                                                                29403789566.34553899906876,
 
  289                                                                170266573776.5398868392998,
 
  290                                                                492612579337.743088758812,
 
  291                                                                560625185622.3951465078242 );
 
  293                static $lg_q1 = array(  67.48212550303777196073036,
 
  294                                                                1113.332393857199323513008,
 
  295                                                                7738.757056935398733233834,
 
  296                                                                27639.87074403340708898585,
 
  297                                                                54993.10206226157329794414,
 
  298                                                                61611.22180066002127833352,
 
  299                                                                36351.27591501940507276287,
 
  300                                                                8785.536302431013170870835 );
 
  301                static $lg_q2 = array(  183.0328399370592604055942,
 
  302                                                                7765.049321445005871323047,
 
  303                                                                133190.3827966074194402448,
 
  304                                                                1136705.821321969608938755,
 
  305                                                                5267964.117437946917577538,
 
  306                                                                13467014.54311101692290052,
 
  307                                                                17827365.30353274213975932,
 
  308                                                                9533095.591844353613395747 );
 
  309                static $lg_q4 = array(  2690.530175870899333379843,
 
  310                                                                639388.5654300092398984238,
 
  311                                                                41355999.30241388052042842,
 
  312                                                                1120872109.61614794137657,
 
  313                                                                14886137286.78813811542398,
 
  314                                                                101680358627.2438228077304,
 
  315                                                                341747634550.7377132798597,
 
  316                                                                446315818741.9713286462081 );
 
  318                static $lg_c  = array(  -0.001910444077728,
 
  320                                                                -5.952379913043012
e-4,
 
  321                                                                7.93650793500350248
e-4,
 
  322                                                                -0.002777777777777681622553,
 
  323                                                                0.08333333333333333331554247,
 
  327        static $lg_frtbig = 2.25e76;
 
  328        static $pnt68    = 0.6796875;
 
  331        if (
$x == self::$_logGammaCache_x) {
 
  338                } elseif (
$y <= 1.5) {
 
  349                        if ($y <= 0.5 || $y >= $pnt68) {
 
  352                                for (
$i = 0; 
$i < 8; ++
$i) {
 
  353                                        $xnum = $xnum * $xm1 + $lg_p1[
$i];
 
  354                                        $xden = $xden * $xm1 + $lg_q1[
$i];
 
  356                                $res = $corr + $xm1 * ($lg_d1 + $xm1 * ($xnum / $xden));
 
  361                                for (
$i = 0; 
$i < 8; ++
$i) {
 
  362                                        $xnum = $xnum * $xm2 + $lg_p2[
$i];
 
  363                                        $xden = $xden * $xm2 + $lg_q2[
$i];
 
  365                                $res = $corr + $xm2 * ($lg_d2 + $xm2 * ($xnum / $xden));
 
  367                } elseif (
$y <= 4.0) {
 
  374                        for (
$i = 0; 
$i < 8; ++
$i) {
 
  375                                $xnum = $xnum * $xm2 + $lg_p2[
$i];
 
  376                                $xden = $xden * $xm2 + $lg_q2[
$i];
 
  378                        $res = $xm2 * ($lg_d2 + $xm2 * ($xnum / $xden));
 
  379                } elseif (
$y <= 12.0) {
 
  386                        for (
$i = 0; 
$i < 8; ++
$i) {
 
  387                                $xnum = $xnum * $xm4 + $lg_p4[
$i];
 
  388                                $xden = $xden * $xm4 + $lg_q4[
$i];
 
  390                        $res = $lg_d4 + $xm4 * ($xnum / $xden);
 
  396                        if (
$y <= $lg_frtbig) {
 
  399                                for (
$i = 0; 
$i < 6; ++
$i)
 
  405                                $res += 
$y * ($corr - 1.0);
 
  416                self::$_logGammaCache_x = 
$x;
 
  417                self::$_logGammaCache_result = 
$res;
 
  428                for (
$n=0; 
$n<=$max; ++
$n) {
 
  431                                $divisor *= ($a + 
$i);
 
  433                        $summer += (pow(
$x,
$n) / $divisor);
 
  435                return pow(
$x,$a) * exp(0-
$x) * $summer;
 
  443                if (
$data == 0.0) 
return 0;
 
  445                static $p0 = 1.000000000190015;
 
  446                static $p = array ( 1 => 76.18009172947146,
 
  447                                                        2 => -86.50532032941677,
 
  448                                                        3 => 24.01409824083091,
 
  449                                                        4 => -1.231739572450155,
 
  450                                                        5 => 1.208650973866179
e-3,
 
  451                                                        6 => -5.395239384953
e-6
 
  456                $tmp -= (
$x + 0.5) * log($tmp);
 
  459                for ($j=1;$j<=6;++$j) {
 
  460                        $summer += ($p[$j] / ++
$y);
 
  462                return exp(0 - $tmp + log(
SQRT2PI * $summer / 
$x));
 
  488                static $a = array(      1 => -3.969683028665376
e+01,
 
  489                                                        2 => 2.209460984245205
e+02,
 
  490                                                        3 => -2.759285104469687
e+02,
 
  491                                                        4 => 1.383577518672690
e+02,
 
  492                                                        5 => -3.066479806614716
e+01,
 
  493                                                        6 => 2.506628277459239
e+00
 
  496                static $b = array(      1 => -5.447609879822406
e+01,
 
  497                                                        2 => 1.615858368580409
e+02,
 
  498                                                        3 => -1.556989798598866
e+02,
 
  499                                                        4 => 6.680131188771972
e+01,
 
  500                                                        5 => -1.328068155288572
e+01
 
  503                static $c = array(      1 => -7.784894002430293
e-03,
 
  504                                                        2 => -3.223964580411365
e-01,
 
  505                                                        3 => -2.400758277161838
e+00,
 
  506                                                        4 => -2.549732539343734
e+00,
 
  507                                                        5 => 4.374664141464968
e+00,
 
  508                                                        6 => 2.938163982698783
e+00
 
  511                static $d = array(      1 => 7.784695709041462
e-03,
 
  512                                                        2 => 3.224671290700398
e-01,
 
  513                                                        3 => 2.445134137142996
e+00,
 
  514                                                        4 => 3.754408661907416
e+00
 
  519                $p_high = 1 - $p_low;           
 
  521                if (0 < $p && $p < $p_low) {
 
  523                        $q = sqrt(-2 * log($p));
 
  524                        return ((((($c[1] * $q + $c[2]) * $q + $c[3]) * $q + $c[4]) * $q + $c[5]) * $q + $c[6]) /
 
  525                                        ((((
$d[1] * $q + 
$d[2]) * $q + 
$d[3]) * $q + 
$d[4]) * $q + 1);
 
  526                } elseif ($p_low <= $p && $p <= $p_high) {
 
  530                        return ((((($a[1] * 
$r + $a[2]) * 
$r + $a[3]) * 
$r + $a[4]) * 
$r + $a[5]) * 
$r + $a[6]) * $q /
 
  531                                   ((((($b[1] * 
$r + $b[2]) * 
$r + $b[3]) * 
$r + $b[4]) * 
$r + $b[5]) * 
$r + 1);
 
  532                } elseif ($p_high < $p && $p < 1) {
 
  534                        $q = sqrt(-2 * log(1 - $p));
 
  535                        return -((((($c[1] * $q + $c[2]) * $q + $c[3]) * $q + $c[4]) * $q + $c[5]) * $q + $c[6]) /
 
  536                                         ((((
$d[1] * $q + 
$d[2]) * $q + 
$d[3]) * $q + 
$d[4]) * $q + 1);
 
  548                $a2 = -18.61500062529;
 
  549                $a3 = 41.39119773534;
 
  550                $a4 = -25.44106049637;
 
  553                $b2 = 23.08336743743;
 
  554                $b3 = -21.06224101826;
 
  557                $c1 = 0.337475482272615;
 
  558                $c2 = 0.976169019091719;
 
  559                $c3 = 0.160797971491821;
 
  560                $c4 = 2.76438810333863E-02;
 
  561                $c5 = 3.8405729373609E-03;
 
  562                $c6 = 3.951896511919E-04;
 
  563                $c7 = 3.21767881768E-05;
 
  564                $c8 = 2.888167364E-07;
 
  565                $c9 = 3.960315187E-07;
 
  568                if (abs(
$y) < 0.42) {
 
  570                        $z = 
$y * ((($a4 * $z + $a3) * $z + $a2) * $z + $a1) / (((($b4 * $z + $b3) * $z + $b2) * $z + $b1) * $z + 1);
 
  573                                $z = log(-log(1 - $prob));
 
  575                                $z = log(-log($prob));
 
  577                        $z = $c1 + $z * ($c2 + $z * ($c3 + $z * ($c4 + $z * ($c5 + $z * ($c6 + $z * ($c7 + $z * ($c8 + $z * $c9)))))));
 
  599                $a0 = 3.3871328727963666080;
 
  600                $a1 = 1.3314166789178437745E+2;
 
  601                $a2 = 1.9715909503065514427E+3;
 
  602                $a3 = 1.3731693765509461125E+4;
 
  603                $a4 = 4.5921953931549871457E+4;
 
  604                $a5 = 6.7265770927008700853E+4;
 
  605                $a6 = 3.3430575583588128105E+4;
 
  606                $a7 = 2.5090809287301226727E+3;
 
  608                $b1 = 4.2313330701600911252E+1;
 
  609                $b2 = 6.8718700749205790830E+2;
 
  610                $b3 = 5.3941960214247511077E+3;
 
  611                $b4 = 2.1213794301586595867E+4;
 
  612                $b5 = 3.9307895800092710610E+4;
 
  613                $b6 = 2.8729085735721942674E+4;
 
  614                $b7 = 5.2264952788528545610E+3;
 
  617                $c0 = 1.42343711074968357734;
 
  618                $c1 = 4.63033784615654529590;
 
  619                $c2 = 5.76949722146069140550;
 
  620                $c3 = 3.64784832476320460504;
 
  621                $c4 = 1.27045825245236838258;
 
  622                $c5 = 2.41780725177450611770E-1;
 
  623                $c6 = 2.27238449892691845833E-2;
 
  624                $c7 = 7.74545014278341407640E-4;
 
  626                $d1 = 2.05319162663775882187;
 
  627                $d2 = 1.67638483018380384940;
 
  628                $d3 = 6.89767334985100004550E-1;
 
  629                $d4 = 1.48103976427480074590E-1;
 
  630                $d5 = 1.51986665636164571966E-2;
 
  631                $d6 = 5.47593808499534494600E-4;
 
  632                $d7 = 1.05075007164441684324E-9;
 
  635                $e0 = 6.65790464350110377720;
 
  636                $e1 = 5.46378491116411436990;
 
  637                $e2 = 1.78482653991729133580;
 
  638                $e3 = 2.96560571828504891230E-1;
 
  639                $e4 = 2.65321895265761230930E-2;
 
  640                $e5 = 1.24266094738807843860E-3;
 
  641                $e6 = 2.71155556874348757815E-5;
 
  642                $e7 = 2.01033439929228813265E-7;
 
  644                $f1 = 5.99832206555887937690E-1;
 
  645                $f2 = 1.36929880922735805310E-1;
 
  646                $f3 = 1.48753612908506148525E-2;
 
  647                $f4 = 7.86869131145613259100E-4;
 
  648                $f5 = 1.84631831751005468180E-5;
 
  649                $f6 = 1.42151175831644588870E-7;
 
  650                $f7 = 2.04426310338993978564E-15;
 
  655                if (abs($q) <= split1) {
 
  656                        $R = $const1 - $q * $q;
 
  657                        $z = $q * ((((((($a7 * $R + $a6) * $R + $a5) * $R + $a4) * $R + $a3) * $R + $a2) * $R + $a1) * $R + $a0) /
 
  658                                          ((((((($b7 * $R + $b6) * $R + $b5) * $R + $b4) * $R + $b3) * $R + $b2) * $R + $b1) * $R + 1);
 
  665                        $R = pow(-log($R),2);
 
  670                                $z = ((((((($c7 * $R + $c6) * $R + $c5) * $R + $c4) * $R + $c3) * $R + $c2) * $R + $c1) * $R + $c0) /
 
  671                                         ((((((($d7 * $R + $d6) * $R + $d5) * $R + $d4) * $R + $d3) * $R + $d2) * $R + $d1) * $R + 1);
 
  675                                $z = ((((((($e7 * $R + $e6) * $R + $e5) * $R + $e4) * $R + $e3) * $R + $e2) * $R + $e1) * $R + $e0) /
 
  676                                         ((((((($f7 * $R + $f6) * $R + $f5) * $R + $f4) * $R + $f3) * $R + $f2) * $R + $f1) * $R + 1);
 
  709                        foreach ($aArgs as $k => $arg) {
 
  710                                if ((is_bool($arg)) &&
 
  712                                        $arg = (integer) $arg;
 
  715                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
  716                                        if (is_null($returnValue)) {
 
  717                                                $returnValue = abs($arg - $aMean);
 
  719                                                $returnValue += abs($arg - $aMean);
 
  729                        return $returnValue / $aCount;
 
  749                $returnValue = $aCount = 0;
 
  753                        if ((is_bool($arg)) &&
 
  755                                $arg = (integer) $arg;
 
  758                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
  759                                if (is_null($returnValue)) {
 
  762                                        $returnValue += $arg;
 
  770                        return $returnValue / $aCount;
 
  797                        if ((is_bool($arg)) &&
 
  800                                if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != 
'')))) {
 
  802                                                $arg = (integer) $arg;
 
  803                                        } elseif (is_string($arg)) {
 
  806                                        if (is_null($returnValue)) {
 
  809                                                $returnValue += $arg;
 
  818                        return $returnValue / $aCount;
 
  840        public static function AVERAGEIF($aArgs,$condition,$averageArgs = array()) {
 
  846                if (empty($averageArgs)) {
 
  847                        $averageArgs = $aArgs;
 
  852                foreach ($aArgs as 
$key => $arg) {
 
  854                        $testCondition = 
'='.$arg.$condition;
 
  856                                if ((is_null($returnValue)) || ($arg > $returnValue)) {
 
  857                                        $returnValue += $arg;
 
  865                        return $returnValue / $aCount;
 
  884        public static function BETADIST($value,$alpha,$beta,$rMin=0,$rMax=1) {
 
  891                if ((is_numeric($value)) && (is_numeric($alpha)) && (is_numeric($beta)) && (is_numeric($rMin)) && (is_numeric($rMax))) {
 
  892                        if (($value < $rMin) || ($value > $rMax) || ($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax)) {
 
  901                        $value /= ($rMax - $rMin);
 
  922        public static function BETAINV($probability,$alpha,$beta,$rMin=0,$rMax=1) {
 
  929                if ((is_numeric($probability)) && (is_numeric($alpha)) && (is_numeric($beta)) && (is_numeric($rMin)) && (is_numeric($rMax))) {
 
  930                        if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0) || ($probability > 1)) {
 
  943                                $guess = ($a + $b) / 2;
 
  947                                } elseif (
$result > $probability) {
 
  956                        return round($rMin + $guess * ($rMax - $rMin),12);
 
  980        public static function BINOMDIST($value, $trials, $probability, $cumulative) {
 
  985                if ((is_numeric($value)) && (is_numeric($trials)) && (is_numeric($probability))) {
 
  986                        if (($value < 0) || ($value > $trials)) {
 
  989                        if (($probability < 0) || ($probability > 1)) {
 
  992                        if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
 
  995                                        for (
$i = 0; 
$i <= $value; ++
$i) {
 
 1017        public static function CHIDIST($value, $degrees) {
 
 1021                if ((is_numeric($value)) && (is_numeric($degrees))) {
 
 1046        public static function CHIINV($probability, $degrees) {
 
 1050                if ((is_numeric($probability)) && (is_numeric($degrees))) {
 
 1065                                } elseif (
$error < 0.0) {
 
 1078                                if (($xNew < $xLo) || ($xNew > $xHi) || (
$result == 0.0)) {
 
 1079                                        $xNew = ($xLo + $xHi) / 2;
 
 1087                        return round(
$x,12);
 
 1109                if ((is_numeric($alpha)) && (is_numeric($stdDev)) && (is_numeric(
$size))) {
 
 1110                        if (($alpha <= 0) || ($alpha >= 1)) {
 
 1113                        if (($stdDev <= 0) || (
$size < 1)) {
 
 1131        public static function CORREL($yValues,$xValues=
null) {
 
 1132                if ((is_null($xValues)) || (!is_array($yValues)) || (!is_array($xValues))) {
 
 1135                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 1138                $yValueCount = count($yValues);
 
 1139                $xValueCount = count($xValues);
 
 1141                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 1143                } elseif ($yValueCount == 1) {
 
 1148                return $bestFitLinear->getCorrelation();
 
 1171                foreach ($aArgs as $k => $arg) {
 
 1172                        if ((is_bool($arg)) &&
 
 1174                                $arg = (integer) $arg;
 
 1177                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1183                return $returnValue;
 
 1206                foreach ($aArgs as $arg) {
 
 1208                        if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != 
'')))) {
 
 1214                return $returnValue;
 
 1237                foreach ($aArgs as $arg) {
 
 1239                        if ((is_null($arg)) || ((is_string($arg)) && ($arg == 
''))) {
 
 1245                return $returnValue;
 
 1263        public static function COUNTIF($aArgs,$condition) {
 
 1270                foreach ($aArgs as $arg) {
 
 1272                        $testCondition = 
'='.$arg.$condition;
 
 1280                return $returnValue;
 
 1293        public static function COVAR($yValues,$xValues) {
 
 1294                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 1297                $yValueCount = count($yValues);
 
 1298                $xValueCount = count($xValues);
 
 1300                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 1302                } elseif ($yValueCount == 1) {
 
 1307                return $bestFitLinear->getCovariance();
 
 1330        public static function CRITBINOM($trials, $probability, $alpha) {
 
 1335                if ((is_numeric($trials)) && (is_numeric($probability)) && (is_numeric($alpha))) {
 
 1339                        if (($probability < 0) || ($probability > 1)) {
 
 1342                        if (($alpha < 0) || ($alpha > 1)) {
 
 1345                        if ($alpha <= 0.5) {
 
 1346                                $t = sqrt(log(1 / ($alpha * $alpha)));
 
 1347                                $trialsApprox = 0 - (
$t + (2.515517 + 0.802853 * 
$t + 0.010328 * 
$t * 
$t) / (1 + 1.432788 * 
$t + 0.189269 * 
$t * 
$t + 0.001308 * 
$t * 
$t * 
$t));
 
 1349                                $t = sqrt(log(1 / pow(1 - $alpha,2)));
 
 1350                                $trialsApprox = 
$t - (2.515517 + 0.802853 * 
$t + 0.010328 * 
$t * 
$t) / (1 + 1.432788 * 
$t + 0.189269 * 
$t * 
$t + 0.001308 * 
$t * 
$t * 
$t);
 
 1352                        $Guess = floor($trials * $probability + $trialsApprox * sqrt($trials * $probability * (1 - $probability)));
 
 1355                        } elseif ($Guess > $trials) {
 
 1359                        $TotalUnscaledProbability = $UnscaledPGuess = $UnscaledCumPGuess = 0.0;
 
 1360                        $EssentiallyZero = 10
e-12;
 
 1362                        $m = floor($trials * $probability);
 
 1363                        ++$TotalUnscaledProbability;
 
 1364                        if (
$m == $Guess) { ++$UnscaledPGuess; }
 
 1365                        if (
$m <= $Guess) { ++$UnscaledCumPGuess; }
 
 1370                        while ((!$Done) && ($k <= $trials)) {
 
 1371                                $CurrentValue = $PreviousValue * ($trials - $k + 1) * $probability / ($k * (1 - $probability));
 
 1372                                $TotalUnscaledProbability += $CurrentValue;
 
 1373                                if ($k == $Guess) { $UnscaledPGuess += $CurrentValue; }
 
 1374                                if ($k <= $Guess) { $UnscaledCumPGuess += $CurrentValue; }
 
 1375                                if ($CurrentValue <= $EssentiallyZero) { $Done = True; }
 
 1376                                $PreviousValue = $CurrentValue;
 
 1383                        while ((!$Done) && ($k >= 0)) {
 
 1384                                $CurrentValue = $PreviousValue * $k + 1 * (1 - $probability) / (($trials - $k) * $probability);
 
 1385                                $TotalUnscaledProbability += $CurrentValue;
 
 1386                                if ($k == $Guess) { $UnscaledPGuess += $CurrentValue; }
 
 1387                                if ($k <= $Guess) { $UnscaledCumPGuess += $CurrentValue; }
 
 1388                                if ($CurrentValue <= $EssentiallyZero) { $Done = True; }
 
 1389                                $PreviousValue = $CurrentValue;
 
 1393                        $PGuess = $UnscaledPGuess / $TotalUnscaledProbability;
 
 1394                        $CumPGuess = $UnscaledCumPGuess / $TotalUnscaledProbability;
 
 1397                        $CumPGuessMinus1 = $CumPGuess - 1;
 
 1400                                if (($CumPGuessMinus1 < $alpha) && ($CumPGuess >= $alpha)) {
 
 1402                                } elseif (($CumPGuessMinus1 < $alpha) && ($CumPGuess < $alpha)) {
 
 1403                                        $PGuessPlus1 = $PGuess * ($trials - $Guess) * $probability / $Guess / (1 - $probability);
 
 1404                                        $CumPGuessMinus1 = $CumPGuess;
 
 1405                                        $CumPGuess = $CumPGuess + $PGuessPlus1;
 
 1406                                        $PGuess = $PGuessPlus1;
 
 1408                                } elseif (($CumPGuessMinus1 >= $alpha) && ($CumPGuess >= $alpha)) {
 
 1409                                        $PGuessMinus1 = $PGuess * $Guess * (1 - $probability) / ($trials - $Guess + 1) / $probability;
 
 1410                                        $CumPGuess = $CumPGuessMinus1;
 
 1411                                        $CumPGuessMinus1 = $CumPGuessMinus1 - $PGuess;
 
 1412                                        $PGuess = $PGuessMinus1;
 
 1438                $returnValue = 
null;
 
 1443                        foreach ($aArgs as $k => $arg) {
 
 1445                                if ((is_bool($arg)) &&
 
 1447                                        $arg = (integer) $arg;
 
 1449                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1450                                        if (is_null($returnValue)) {
 
 1451                                                $returnValue = pow(($arg - $aMean),2);
 
 1453                                                $returnValue += pow(($arg - $aMean),2);
 
 1460                        if (is_null($returnValue)) {
 
 1463                                return $returnValue;
 
 1482        public static function EXPONDIST($value, $lambda, $cumulative) {
 
 1487                if ((is_numeric($value)) && (is_numeric($lambda))) {
 
 1488                        if (($value < 0) || ($lambda < 0)) {
 
 1491                        if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
 
 1493                                        return 1 - exp(0-$value*$lambda);
 
 1495                                        return $lambda * exp(0-$value*$lambda);
 
 1516                if (is_numeric($value)) {
 
 1517                        if (($value <= -1) || ($value >= 1)) {
 
 1520                        return 0.5 * log((1+$value)/(1-$value));
 
 1539                if (is_numeric($value)) {
 
 1540                        return (exp(2 * $value) - 1) / (exp(2 * $value) + 1);
 
 1556        public static function FORECAST($xValue,$yValues,$xValues) {
 
 1558                if (!is_numeric($xValue)) {
 
 1562                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 1565                $yValueCount = count($yValues);
 
 1566                $xValueCount = count($xValues);
 
 1568                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 1570                } elseif ($yValueCount == 1) {
 
 1575                return $bestFitLinear->getValueOfYForX($xValue);
 
 1591        public static function GAMMADIST($value,$a,$b,$cumulative) {
 
 1596                if ((is_numeric($value)) && (is_numeric($a)) && (is_numeric($b))) {
 
 1597                        if (($value < 0) || ($a <= 0) || ($b <= 0)) {
 
 1600                        if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
 
 1604                                        return (1 / (pow($b,$a) * self::_gamma($a))) * pow($value,$a-1) * exp(0-($value / $b));
 
 1623        public static function GAMMAINV($probability,$alpha,$beta) {
 
 1628                if ((is_numeric($probability)) && (is_numeric($alpha)) && (is_numeric($beta))) {
 
 1629                        if (($alpha <= 0) || ($beta <= 0) || ($probability < 0) || ($probability > 1)) {
 
 1634                        $xHi = $alpha * $beta * 5;
 
 1658                                if (($xNew < $xLo) || ($xNew > $xHi) || (
$pdf == 0.0)) {
 
 1659                                        $xNew = ($xLo + $xHi) / 2;
 
 1684                if (is_numeric($value)) {
 
 1688                        return log(self::_gamma($value));
 
 1713                if (is_numeric($aMean) && ($aMean > 0)) {
 
 1715                        if (self::MIN($aArgs) > 0) {
 
 1716                                return pow($aMean, (1 / $aCount));
 
 1734        public static function GROWTH($yValues,$xValues=array(),$newValues=array(),$const=True) {
 
 1741                if (empty($newValues)) {
 
 1742                        $newValues = $bestFitExponential->getXValues();
 
 1745                $returnArray = array();
 
 1746                foreach($newValues as $xValue) {
 
 1747                        $returnArray[0][] = $bestFitExponential->getValueOfYForX($xValue);
 
 1750                return $returnArray;
 
 1774                if (self::MIN($aArgs) < 0) {
 
 1778                foreach ($aArgs as $arg) {
 
 1780                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1784                                if (is_null($returnValue)) {
 
 1785                                        $returnValue = (1 / $arg);
 
 1787                                        $returnValue += (1 / $arg);
 
 1795                        return 1 / ($returnValue / $aCount);
 
 1797                        return $returnValue;
 
 1815        public static function HYPGEOMDIST($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber) {
 
 1821                if ((is_numeric($sampleSuccesses)) && (is_numeric($sampleNumber)) && (is_numeric($populationSuccesses)) && (is_numeric($populationNumber))) {
 
 1822                        if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) {
 
 1825                        if (($sampleNumber <= 0) || ($sampleNumber > $populationNumber)) {
 
 1828                        if (($populationSuccesses <= 0) || ($populationSuccesses > $populationNumber)) {
 
 1849                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 1852                $yValueCount = count($yValues);
 
 1853                $xValueCount = count($xValues);
 
 1855                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 1857                } elseif ($yValueCount == 1) {
 
 1862                return $bestFitLinear->getIntersect();
 
 1883                        $count = $summer = 0;
 
 1885                        foreach ($aArgs as $k => $arg) {
 
 1886                                if ((is_bool($arg)) &&
 
 1890                                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1891                                                $summer += pow((($arg - $mean) / $stdDev),4) ;
 
 1899                                return $summer * ($count * ($count+1) / (($count-1) * ($count-2) * ($count-3))) - (3 * pow($count-1,2) / (($count-2) * ($count-3)));
 
 1926                $entry = floor(array_pop($aArgs));
 
 1928                if ((is_numeric($entry)) && (!is_string($entry))) {
 
 1930                        foreach ($aArgs as $arg) {
 
 1932                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 1937                        $entry = floor(--$entry);
 
 1938                        if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
 
 1942                        return $mArgs[$entry];
 
 1960        public static function LINEST($yValues, $xValues = NULL, $const = TRUE, 
$stats = FALSE) {
 
 1965                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 1968                $yValueCount = count($yValues);
 
 1969                $xValueCount = count($xValues);
 
 1972                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 1974                } elseif ($yValueCount == 1) {
 
 1980                        return array( array( $bestFitLinear->getSlope(),
 
 1981                                                                 $bestFitLinear->getSlopeSE(),
 
 1982                                                                 $bestFitLinear->getGoodnessOfFit(),
 
 1983                                                                 $bestFitLinear->getF(),
 
 1984                                                                 $bestFitLinear->getSSRegression(),
 
 1986                                                  array( $bestFitLinear->getIntersect(),
 
 1987                                                                 $bestFitLinear->getIntersectSE(),
 
 1988                                                                 $bestFitLinear->getStdevOfResiduals(),
 
 1989                                                                 $bestFitLinear->getDFResiduals(),
 
 1990                                                                 $bestFitLinear->getSSResiduals()
 
 1994                        return array( $bestFitLinear->getSlope(),
 
 1995                                                  $bestFitLinear->getIntersect()
 
 2013        public static function LOGEST($yValues,$xValues=
null,$const=True,
$stats=False) {
 
 2018                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 2021                $yValueCount = count($yValues);
 
 2022                $xValueCount = count($xValues);
 
 2024                foreach($yValues as $value) {
 
 2025                        if ($value <= 0.0) {
 
 2031                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 2033                } elseif ($yValueCount == 1) {
 
 2039                        return array( array( $bestFitExponential->getSlope(),
 
 2040                                                                 $bestFitExponential->getSlopeSE(),
 
 2041                                                                 $bestFitExponential->getGoodnessOfFit(),
 
 2042                                                                 $bestFitExponential->getF(),
 
 2043                                                                 $bestFitExponential->getSSRegression(),
 
 2045                                                  array( $bestFitExponential->getIntersect(),
 
 2046                                                                 $bestFitExponential->getIntersectSE(),
 
 2047                                                                 $bestFitExponential->getStdevOfResiduals(),
 
 2048                                                                 $bestFitExponential->getDFResiduals(),
 
 2049                                                                 $bestFitExponential->getSSResiduals()
 
 2053                        return array( $bestFitExponential->getSlope(),
 
 2054                                                  $bestFitExponential->getIntersect()
 
 2074        public static function LOGINV($probability, $mean, $stdDev) {
 
 2079                if ((is_numeric($probability)) && (is_numeric($mean)) && (is_numeric($stdDev))) {
 
 2080                        if (($probability < 0) || ($probability > 1) || ($stdDev <= 0)) {
 
 2083                        return exp($mean + $stdDev * self::NORMSINV($probability));
 
 2105                if ((is_numeric($value)) && (is_numeric($mean)) && (is_numeric($stdDev))) {
 
 2106                        if (($value <= 0) || ($stdDev <= 0)) {
 
 2129        public static function MAX() {
 
 2131                $returnValue = 
null;
 
 2135                foreach ($aArgs as $arg) {
 
 2137                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2138                                if ((is_null($returnValue)) || ($arg > $returnValue)) {
 
 2139                                        $returnValue = $arg;
 
 2145                if(is_null($returnValue)) {
 
 2148                return $returnValue;
 
 2167                $returnValue = 
null;
 
 2171                foreach ($aArgs as $arg) {
 
 2173                        if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != 
'')))) {
 
 2174                                if (is_bool($arg)) {
 
 2175                                        $arg = (integer) $arg;
 
 2176                                } elseif (is_string($arg)) {
 
 2179                                if ((is_null($returnValue)) || ($arg > $returnValue)) {
 
 2180                                        $returnValue = $arg;
 
 2186                if(is_null($returnValue)) {
 
 2189                return $returnValue;
 
 2207        public static function MAXIF($aArgs,$condition,$sumArgs = array()) {
 
 2209                $returnValue = 
null;
 
 2213                if (empty($sumArgs)) {
 
 2218                foreach ($aArgs as 
$key => $arg) {
 
 2220                        $testCondition = 
'='.$arg.$condition;
 
 2222                                if ((is_null($returnValue)) || ($arg > $returnValue)) {
 
 2223                                        $returnValue = $arg;
 
 2229                return $returnValue;
 
 2253                foreach ($aArgs as $arg) {
 
 2255                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2260                $mValueCount = count($mArgs);
 
 2261                if ($mValueCount > 0) {
 
 2262                        sort($mArgs,SORT_NUMERIC);
 
 2263                        $mValueCount = $mValueCount / 2;
 
 2264                        if ($mValueCount == floor($mValueCount)) {
 
 2265                                $returnValue = ($mArgs[$mValueCount--] + $mArgs[$mValueCount]) / 2;
 
 2267                                $mValueCount == floor($mValueCount);
 
 2268                                $returnValue = $mArgs[$mValueCount];
 
 2273                return $returnValue;
 
 2291        public static function MIN() {
 
 2293                $returnValue = 
null;
 
 2297                foreach ($aArgs as $arg) {
 
 2299                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2300                                if ((is_null($returnValue)) || ($arg < $returnValue)) {
 
 2301                                        $returnValue = $arg;
 
 2307                if(is_null($returnValue)) {
 
 2310                return $returnValue;
 
 2329                $returnValue = 
null;
 
 2333                foreach ($aArgs as $arg) {
 
 2335                        if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != 
'')))) {
 
 2336                                if (is_bool($arg)) {
 
 2337                                        $arg = (integer) $arg;
 
 2338                                } elseif (is_string($arg)) {
 
 2341                                if ((is_null($returnValue)) || ($arg < $returnValue)) {
 
 2342                                        $returnValue = $arg;
 
 2348                if(is_null($returnValue)) {
 
 2351                return $returnValue;
 
 2369        public static function MINIF($aArgs,$condition,$sumArgs = array()) {
 
 2371                $returnValue = 
null;
 
 2375                if (empty($sumArgs)) {
 
 2380                foreach ($aArgs as 
$key => $arg) {
 
 2382                        $testCondition = 
'='.$arg.$condition;
 
 2384                                if ((is_null($returnValue)) || ($arg < $returnValue)) {
 
 2385                                        $returnValue = $arg;
 
 2391                return $returnValue;
 
 2400                $frequencyArray = array();
 
 2401                foreach(
$data as $datum) {
 
 2403                        foreach($frequencyArray as 
$key => $value) {
 
 2404                                if ((
string) $value[
'value'] == (
string) $datum) {
 
 2405                                        ++$frequencyArray[
$key][
'frequency'];
 
 2411                                $frequencyArray[] = array(
'value'               => $datum,
 
 2416                foreach($frequencyArray as 
$key => $value) {
 
 2417                        $frequencyList[
$key] = $value[
'frequency'];
 
 2418                        $valueList[
$key] = $value[
'value'];
 
 2420                array_multisort($frequencyList, SORT_DESC, $valueList, SORT_ASC, SORT_NUMERIC, $frequencyArray);
 
 2422                if ($frequencyArray[0][
'frequency'] == 1) {
 
 2425                return $frequencyArray[0][
'value'];
 
 2450                foreach ($aArgs as $arg) {
 
 2452                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2457                if (!empty($mArgs)) {
 
 2462                return $returnValue;
 
 2486                if ((is_numeric($failures)) && (is_numeric($successes)) && (is_numeric($probability))) {
 
 2487                        if (($failures < 0) || ($successes < 1)) {
 
 2490                        if (($probability < 0) || ($probability > 1)) {
 
 2494                                if (($failures + $successes - 1) <= 0) {
 
 2518        public static function NORMDIST($value, $mean, $stdDev, $cumulative) {
 
 2523                if ((is_numeric($value)) && (is_numeric($mean)) && (is_numeric($stdDev))) {
 
 2527                        if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
 
 2531                                        return (1 / (
SQRT2PI * $stdDev)) * exp(0 - (pow($value - $mean,2) / (2 * ($stdDev * $stdDev))));
 
 2550        public static function NORMINV($probability,$mean,$stdDev) {
 
 2555                if ((is_numeric($probability)) && (is_numeric($mean)) && (is_numeric($stdDev))) {
 
 2556                        if (($probability < 0) || ($probability > 1)) {
 
 2562                        return (self::_inverse_ncdf($probability) * $stdDev) + $mean;
 
 2616                $entry = array_pop($aArgs);
 
 2618                if ((is_numeric($entry)) && (!is_string($entry))) {
 
 2619                        if (($entry < 0) || ($entry > 1)) {
 
 2623                        foreach ($aArgs as $arg) {
 
 2625                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2629                        $mValueCount = count($mArgs);
 
 2630                        if ($mValueCount > 0) {
 
 2633                                $index = $entry * ($count-1);
 
 2638                                        $iNext = $iBase + 1;
 
 2639                                        $iProportion = 
$index - $iBase;
 
 2640                                        return $mArgs[$iBase] + (($mArgs[$iNext] - $mArgs[$iBase]) * $iProportion) ;
 
 2658        public static function PERCENTRANK($valueSet,$value,$significance=3) {
 
 2663                foreach($valueSet as 
$key => $valueEntry) {
 
 2664                        if (!is_numeric($valueEntry)) {
 
 2665                                unset($valueSet[
$key]);
 
 2668                sort($valueSet,SORT_NUMERIC);
 
 2669                $valueCount = count($valueSet);
 
 2670                if ($valueCount == 0) {
 
 2674                $valueAdjustor = $valueCount - 1;
 
 2675                if (($value < $valueSet[0]) || ($value > $valueSet[$valueAdjustor])) {
 
 2679                $pos = array_search($value,$valueSet);
 
 2680                if ($pos === False) {
 
 2682                        $testValue = $valueSet[0];
 
 2683                        while ($testValue < $value) {
 
 2684                                $testValue = $valueSet[++$pos];
 
 2687                        $pos += (($value - $valueSet[$pos]) / ($testValue - $valueSet[$pos]));
 
 2690                return round($pos / $valueAdjustor,$significance);
 
 2707        public static function PERMUT($numObjs,$numInSet) {
 
 2711                if ((is_numeric($numObjs)) && (is_numeric($numInSet))) {
 
 2712                        $numInSet = floor($numInSet);
 
 2713                        if ($numObjs < $numInSet) {
 
 2735        public static function POISSON($value, $mean, $cumulative) {
 
 2739                if ((is_numeric($value)) && (is_numeric($mean))) {
 
 2740                        if (($value < 0) || ($mean <= 0)) {
 
 2743                        if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
 
 2746                                        for (
$i = 0; 
$i <= floor($value); ++
$i) {
 
 2749                                        return exp(0-$mean) * $summer;
 
 2777                $entry = floor(array_pop($aArgs));
 
 2779                if ((is_numeric($entry)) && (!is_string($entry))) {
 
 2781                        if (($entry < 0) || ($entry > 1)) {
 
 2800        public static function RANK($value,$valueSet,$order=0) {
 
 2805                foreach($valueSet as 
$key => $valueEntry) {
 
 2806                        if (!is_numeric($valueEntry)) {
 
 2807                                unset($valueSet[
$key]);
 
 2812                        rsort($valueSet,SORT_NUMERIC);
 
 2814                        sort($valueSet,SORT_NUMERIC);
 
 2816                $pos = array_search($value,$valueSet);
 
 2817                if ($pos === False) {
 
 2834        public static function RSQ($yValues,$xValues) {
 
 2835                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 2838                $yValueCount = count($yValues);
 
 2839                $xValueCount = count($xValues);
 
 2841                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 2843                } elseif ($yValueCount == 1) {
 
 2848                return $bestFitLinear->getGoodnessOfFit();
 
 2868                $count = $summer = 0;
 
 2870                foreach ($aArgs as $k => $arg) {
 
 2871                        if ((is_bool($arg)) &&
 
 2875                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2876                                        $summer += pow((($arg - $mean) / $stdDev),3) ;
 
 2884                        return $summer * ($count / (($count-1) * ($count-2)));
 
 2899        public static function SLOPE($yValues,$xValues) {
 
 2900                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 2903                $yValueCount = count($yValues);
 
 2904                $xValueCount = count($xValues);
 
 2906                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 2908                } elseif ($yValueCount == 1) {
 
 2913                return $bestFitLinear->getSlope();
 
 2936                $entry = array_pop($aArgs);
 
 2938                if ((is_numeric($entry)) && (!is_string($entry))) {
 
 2940                        foreach ($aArgs as $arg) {
 
 2942                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 2947                        $entry = floor(--$entry);
 
 2948                        if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
 
 2952                        return $mArgs[$entry];
 
 2973                if ((is_numeric($value)) && (is_numeric($mean)) && (is_numeric($stdDev))) {
 
 2977                        return ($value - $mean) / $stdDev ;
 
 3001                $returnValue = 
null;
 
 3004                if (!is_null($aMean)) {
 
 3006                        foreach ($aArgs as $k => $arg) {
 
 3007                                if ((is_bool($arg)) &&
 
 3009                                        $arg = (integer) $arg;
 
 3012                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 3013                                        if (is_null($returnValue)) {
 
 3014                                                $returnValue = pow(($arg - $aMean),2);
 
 3016                                                $returnValue += pow(($arg - $aMean),2);
 
 3023                        if (($aCount > 0) && ($returnValue >= 0)) {
 
 3024                                return sqrt($returnValue / $aCount);
 
 3048                $returnValue = 
null;
 
 3051                if (!is_null($aMean)) {
 
 3053                        foreach ($aArgs as $k => $arg) {
 
 3054                                if ((is_bool($arg)) &&
 
 3058                                        if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) & ($arg != 
'')))) {
 
 3059                                                if (is_bool($arg)) {
 
 3060                                                        $arg = (integer) $arg;
 
 3061                                                } elseif (is_string($arg)) {
 
 3064                                                if (is_null($returnValue)) {
 
 3065                                                        $returnValue = pow(($arg - $aMean),2);
 
 3067                                                        $returnValue += pow(($arg - $aMean),2);
 
 3075                        if (($aCount > 0) && ($returnValue >= 0)) {
 
 3076                                return sqrt($returnValue / $aCount);
 
 3100                $returnValue = 
null;
 
 3103                if (!is_null($aMean)) {
 
 3105                        foreach ($aArgs as $k => $arg) {
 
 3106                                if ((is_bool($arg)) &&
 
 3108                                        $arg = (integer) $arg;
 
 3111                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 3112                                        if (is_null($returnValue)) {
 
 3113                                                $returnValue = pow(($arg - $aMean),2);
 
 3115                                                $returnValue += pow(($arg - $aMean),2);
 
 3122                        if (($aCount > 0) && ($returnValue >= 0)) {
 
 3123                                return sqrt($returnValue / $aCount);
 
 3147                $returnValue = 
null;
 
 3150                if (!is_null($aMean)) {
 
 3152                        foreach ($aArgs as $k => $arg) {
 
 3153                                if ((is_bool($arg)) &&
 
 3157                                        if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) & ($arg != 
'')))) {
 
 3158                                                if (is_bool($arg)) {
 
 3159                                                        $arg = (integer) $arg;
 
 3160                                                } elseif (is_string($arg)) {
 
 3163                                                if (is_null($returnValue)) {
 
 3164                                                        $returnValue = pow(($arg - $aMean),2);
 
 3166                                                        $returnValue += pow(($arg - $aMean),2);
 
 3174                        if (($aCount > 0) && ($returnValue >= 0)) {
 
 3175                                return sqrt($returnValue / $aCount);
 
 3191        public static function STEYX($yValues,$xValues) {
 
 3192                if (!self::_checkTrendArrays($yValues,$xValues)) {
 
 3195                $yValueCount = count($yValues);
 
 3196                $xValueCount = count($xValues);
 
 3198                if (($yValueCount == 0) || ($yValueCount != $xValueCount)) {
 
 3200                } elseif ($yValueCount == 1) {
 
 3205                return $bestFitLinear->getStdevOfResiduals();
 
 3219        public static function TDIST($value, $degrees, $tails) {
 
 3224                if ((is_numeric($value)) && (is_numeric($degrees)) && (is_numeric($tails))) {
 
 3225                        if (($value < 0) || ($degrees < 1) || ($tails < 1) || ($tails > 2)) {
 
 3238                        $ttheta = atan2($value,sqrt($tterm));
 
 3243                        if (($degrees % 2) == 1) {
 
 3252                        while ($ti < $degrees) {
 
 3253                                $tterm *= $tc * $tc * ($ti - 1) / $ti;
 
 3258                        if (($degrees % 2) == 1) { $tsum = 
M_2DIVPI * ($tsum + $ttheta); }
 
 3259                        $tValue = 0.5 * (1 + $tsum);
 
 3261                                return 1 - abs($tValue);
 
 3263                                return 1 - abs((1 - $tValue) - $tValue);
 
 3279        public static function TINV($probability, $degrees) {
 
 3283                if ((is_numeric($probability)) && (is_numeric($degrees))) {
 
 3297                                } elseif (
$error < 0.0) {
 
 3310                                if (($xNew < $xLo) || ($xNew > $xHi) || (
$result == 0.0)) {
 
 3311                                        $xNew = ($xLo + $xHi) / 2;
 
 3319                        return round(
$x,12);
 
 3336        public static function TREND($yValues,$xValues=array(),$newValues=array(),$const=True) {
 
 3343                if (empty($newValues)) {
 
 3344                        $newValues = $bestFitLinear->getXValues();
 
 3347                $returnArray = array();
 
 3348                foreach($newValues as $xValue) {
 
 3349                        $returnArray[0][] = $bestFitLinear->getValueOfYForX($xValue);
 
 3352                return $returnArray;
 
 3376                $percent = array_pop($aArgs);
 
 3378                if ((is_numeric($percent)) && (!is_string($percent))) {
 
 3379                        if (($percent < 0) || ($percent > 1)) {
 
 3383                        foreach ($aArgs as $arg) {
 
 3385                                if ((is_numeric($arg)) && (!is_string($arg))) {
 
 3389                        $discard = floor(self::COUNT($mArgs) * $percent / 2);
 
 3391                        for (
$i=0; 
$i < $discard; ++
$i) {
 
 3393                                array_shift($mArgs);
 
 3418                $summerA = $summerB = 0;
 
 3423                foreach ($aArgs as $arg) {
 
 3424                        if (is_bool($arg)) { $arg = (integer) $arg; }
 
 3426                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 3427                                $summerA += ($arg * $arg);
 
 3435                        $summerA *= $aCount;
 
 3436                        $summerB *= $summerB;
 
 3437                        $returnValue = ($summerA - $summerB) / ($aCount * ($aCount - 1));
 
 3439                return $returnValue;
 
 3460                $summerA = $summerB = 0;
 
 3465                foreach ($aArgs as $k => $arg) {
 
 3466                        if ((is_string($arg)) &&
 
 3469                        } elseif ((is_string($arg)) &&
 
 3473                                if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) & ($arg != 
'')))) {
 
 3474                                        if (is_bool($arg)) {
 
 3475                                                $arg = (integer) $arg;
 
 3476                                        } elseif (is_string($arg)) {
 
 3479                                        $summerA += ($arg * $arg);
 
 3488                        $summerA *= $aCount;
 
 3489                        $summerB *= $summerB;
 
 3490                        $returnValue = ($summerA - $summerB) / ($aCount * ($aCount - 1));
 
 3492                return $returnValue;
 
 3513                $summerA = $summerB = 0;
 
 3518                foreach ($aArgs as $arg) {
 
 3519                        if (is_bool($arg)) { $arg = (integer) $arg; }
 
 3521                        if ((is_numeric($arg)) && (!is_string($arg))) {
 
 3522                                $summerA += ($arg * $arg);
 
 3530                        $summerA *= $aCount;
 
 3531                        $summerB *= $summerB;
 
 3532                        $returnValue = ($summerA - $summerB) / ($aCount * $aCount);
 
 3534                return $returnValue;
 
 3555                $summerA = $summerB = 0;
 
 3560                foreach ($aArgs as $k => $arg) {
 
 3561                        if ((is_string($arg)) &&
 
 3564                        } elseif ((is_string($arg)) &&
 
 3568                                if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) & ($arg != 
'')))) {
 
 3569                                        if (is_bool($arg)) {
 
 3570                                                $arg = (integer) $arg;
 
 3571                                        } elseif (is_string($arg)) {
 
 3574                                        $summerA += ($arg * $arg);
 
 3583                        $summerA *= $aCount;
 
 3584                        $summerB *= $summerB;
 
 3585                        $returnValue = ($summerA - $summerB) / ($aCount * $aCount);
 
 3587                return $returnValue;
 
 3604        public static function WEIBULL($value, $alpha, $beta, $cumulative) {
 
 3609                if ((is_numeric($value)) && (is_numeric($alpha)) && (is_numeric($beta))) {
 
 3610                        if (($value < 0) || ($alpha <= 0) || ($beta <= 0)) {
 
 3613                        if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
 
 3615                                        return 1 - exp(0 - pow($value / $beta,$alpha));
 
 3617                                        return ($alpha / pow($beta,$alpha)) * pow($value,$alpha - 1) * exp(0 - pow($value / $beta,$alpha));
 
 3638        public static function ZTEST($dataSet, $m0, $sigma = NULL) {
 
 3643                if (is_null($sigma)) {
 
 3646                $n = count($dataSet);
 
const MAX_ITERATIONS
MAX_ITERATIONS.
const MAX_VALUE(!defined('PHPEXCEL_ROOT'))
PHPExcel root directory.
const PRECISION
PRECISION.
const LOG_GAMMA_X_MAX_VALUE
LOG_GAMMA_X_MAX_VALUE.
An exception for terminatinating execution or to throw for unit testing.
static isMatrixValue($idx)
static getCompatibilityMode()
static _ifCondition($condition)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
const COMPATIBILITY_GNUMERIC
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static flattenArrayIndexed($array)
Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing.
const COMPATIBILITY_OPENOFFICE
static COMBIN($numObjs, $numInSet)
static NORMINV($probability, $mean, $stdDev)
NORMINV.
static NEGBINOMDIST($failures, $successes, $probability)
NEGBINOMDIST.
static RSQ($yValues, $xValues)
RSQ.
static NORMDIST($value, $mean, $stdDev, $cumulative)
NORMDIST.
static STANDARDIZE($value, $mean, $stdDev)
STANDARDIZE.
static _checkTrendArrays(&$array1, &$array2)
static COVAR($yValues, $xValues)
COVAR.
static GROWTH($yValues, $xValues=array(), $newValues=array(), $const=True)
GROWTH.
static ZTEST($dataSet, $m0, $sigma=NULL)
ZTEST.
static HYPGEOMDIST($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber)
HYPGEOMDIST.
static FISHER($value)
FISHER.
static EXPONDIST($value, $lambda, $cumulative)
EXPONDIST.
static LOGNORMDIST($value, $mean, $stdDev)
LOGNORMDIST.
static NORMSDIST($value)
NORMSDIST.
static _logBeta($p, $q)
The natural logarithm of the beta function.
static CHIINV($probability, $degrees)
CHIINV.
static $_logBetaCache_result
static LOGEST($yValues, $xValues=null, $const=True, $stats=False)
LOGEST.
static FISHERINV($value)
FISHERINV.
static TDIST($value, $degrees, $tails)
TDIST.
static _beta($p, $q)
Beta function.
static SLOPE($yValues, $xValues)
SLOPE.
static $_logGammaCache_result
logGamma function
static WEIBULL($value, $alpha, $beta, $cumulative)
WEIBULL.
static PERCENTRANK($valueSet, $value, $significance=3)
PERCENTRANK.
static CHIDIST($value, $degrees)
CHIDIST.
static AVERAGEIF($aArgs, $condition, $averageArgs=array())
static NORMSINV($value)
NORMSINV.
static STEYX($yValues, $xValues)
STEYX.
static RANK($value, $valueSet, $order=0)
RANK.
static GAMMALN($value)
GAMMALN.
static BINOMDIST($value, $trials, $probability, $cumulative)
BINOMDIST.
static _incompleteGamma($a, $x)
static LINEST($yValues, $xValues=NULL, $const=TRUE, $stats=FALSE)
LINEST.
static CONFIDENCE($alpha, $stdDev, $size)
CONFIDENCE.
static MAXIF($aArgs, $condition, $sumArgs=array())
static CRITBINOM($trials, $probability, $alpha)
CRITBINOM.
static _inverse_ncdf2($prob)
static COUNTIF($aArgs, $condition)
static TINV($probability, $degrees)
TINV.
static INTERCEPT($yValues, $xValues)
INTERCEPT.
static _incompleteBeta($x, $p, $q)
Incomplete beta function.
static FORECAST($xValue, $yValues, $xValues)
FORECAST.
static BETAINV($probability, $alpha, $beta, $rMin=0, $rMax=1)
BETAINV.
static GAMMADIST($value, $a, $b, $cumulative)
GAMMADIST.
static _betaFraction($x, $p, $q)
Evaluates of continued fraction part of incomplete beta function.
static TREND($yValues, $xValues=array(), $newValues=array(), $const=True)
TREND.
static CORREL($yValues, $xValues=null)
CORREL.
static _inverse_ncdf3($p)
static MINIF($aArgs, $condition, $sumArgs=array())
static POISSON($value, $mean, $cumulative)
POISSON.
static LOGINV($probability, $mean, $stdDev)
LOGINV.
static GAMMAINV($probability, $alpha, $beta)
GAMMAINV.
static PERMUT($numObjs, $numInSet)
PERMUT.
static BETADIST($value, $alpha, $beta, $rMin=0, $rMax=1)
BETADIST.
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static _wrapResult($value)
Wrap string values in quotes.
static calculate($trendType=self::TREND_BEST_FIT, $yValues, $xValues=array(), $const=True)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
foreach($_POST as $key=> $value) $res