You are here

public static function PHPExcel_Calculation_Statistical::NEGBINOMDIST 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::NEGBINOMDIST()

* NEGBINOMDIST * * Returns the negative binomial distribution. NEGBINOMDIST returns the probability that * there will be number_f failures before the number_s-th success, when the constant * probability of a success is probability_s. This function is similar to the binomial * distribution, except that the number of successes is fixed, and the number of trials is * variable. Like the binomial, trials are assumed to be independent. * *

Parameters

float $failures Number of Failures: * @param float $successes Threshold number of Successes * @param float $probability Probability of success on each trial * @return float *

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function NEGBINOMDIST($failures, $successes, $probability) {
  $failures = floor(PHPExcel_Calculation_Functions::flattenSingleValue($failures));
  $successes = floor(PHPExcel_Calculation_Functions::flattenSingleValue($successes));
  $probability = PHPExcel_Calculation_Functions::flattenSingleValue($probability);
  if (is_numeric($failures) && is_numeric($successes) && is_numeric($probability)) {
    if ($failures < 0 || $successes < 1) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if ($probability < 0 || $probability > 1) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
      if ($failures + $successes - 1 <= 0) {
        return PHPExcel_Calculation_Functions::NaN();
      }
    }
    return PHPExcel_Calculation_MathTrig::COMBIN($failures + $successes - 1, $successes - 1) * pow($probability, $successes) * pow(1 - $probability, $failures);
  }
  return PHPExcel_Calculation_Functions::VALUE();
}