You are here

public static function PHPExcel_Calculation_Statistical::POISSON in Loft Data Grids 6.2

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

* POISSON * * Returns the Poisson distribution. A common application of the Poisson distribution * is predicting the number of events over a specific time, such as the number of * cars arriving at a toll plaza in 1 minute. * *

Parameters

float $value: * @param float $mean Mean Value * @param boolean $cumulative * @return float *

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function POISSON($value, $mean, $cumulative) {
  $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  $mean = PHPExcel_Calculation_Functions::flattenSingleValue($mean);
  if (is_numeric($value) && is_numeric($mean)) {
    if ($value < 0 || $mean <= 0) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if (is_numeric($cumulative) || is_bool($cumulative)) {
      if ($cumulative) {
        $summer = 0;
        for ($i = 0; $i <= floor($value); ++$i) {
          $summer += pow($mean, $i) / PHPExcel_Calculation_MathTrig::FACT($i);
        }
        return exp(0 - $mean) * $summer;
      }
      else {
        return exp(0 - $mean) * pow($mean, $value) / PHPExcel_Calculation_MathTrig::FACT($value);
      }
    }
  }
  return PHPExcel_Calculation_Functions::VALUE();
}