You are here

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

* BINOMDIST * * Returns the individual term binomial distribution probability. Use BINOMDIST in problems with * a fixed number of tests or trials, when the outcomes of any trial are only success or failure, * when trials are independent, and when the probability of success is constant throughout the * experiment. For example, BINOMDIST can calculate the probability that two of the next three * babies born are male. * *

Parameters

float $value Number of successes in trials: * @param float $trials Number of trials * @param float $probability Probability of success on each trial * @param boolean $cumulative * @return float * * @todo Cumulative distribution function *

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function BINOMDIST($value, $trials, $probability, $cumulative) {
  $value = floor(PHPExcel_Calculation_Functions::flattenSingleValue($value));
  $trials = floor(PHPExcel_Calculation_Functions::flattenSingleValue($trials));
  $probability = PHPExcel_Calculation_Functions::flattenSingleValue($probability);
  if (is_numeric($value) && is_numeric($trials) && is_numeric($probability)) {
    if ($value < 0 || $value > $trials) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if ($probability < 0 || $probability > 1) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if (is_numeric($cumulative) || is_bool($cumulative)) {
      if ($cumulative) {
        $summer = 0;
        for ($i = 0; $i <= $value; ++$i) {
          $summer += PHPExcel_Calculation_MathTrig::COMBIN($trials, $i) * pow($probability, $i) * pow(1 - $probability, $trials - $i);
        }
        return $summer;
      }
      else {
        return PHPExcel_Calculation_MathTrig::COMBIN($trials, $value) * pow($probability, $value) * pow(1 - $probability, $trials - $value);
      }
    }
  }
  return PHPExcel_Calculation_Functions::VALUE();
}