You are here

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

* BETAINV * * Returns the inverse of the beta distribution. * *

Parameters

float $probability Probability at which you want to evaluate the distribution: * @param float $alpha Parameter to the distribution * @param float $beta Parameter to the distribution * @param float $rMin Minimum value * @param float $rMax Maximum value * @param boolean $cumulative * @return float *

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function BETAINV($probability, $alpha, $beta, $rMin = 0, $rMax = 1) {
  $probability = PHPExcel_Calculation_Functions::flattenSingleValue($probability);
  $alpha = PHPExcel_Calculation_Functions::flattenSingleValue($alpha);
  $beta = PHPExcel_Calculation_Functions::flattenSingleValue($beta);
  $rMin = PHPExcel_Calculation_Functions::flattenSingleValue($rMin);
  $rMax = PHPExcel_Calculation_Functions::flattenSingleValue($rMax);
  if (is_numeric($probability) && is_numeric($alpha) && is_numeric($beta) && is_numeric($rMin) && is_numeric($rMax)) {
    if ($alpha <= 0 || $beta <= 0 || $rMin == $rMax || $probability <= 0 || $probability > 1) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if ($rMin > $rMax) {
      $tmp = $rMin;
      $rMin = $rMax;
      $rMax = $tmp;
    }
    $a = 0;
    $b = 2;
    $i = 0;
    while ($b - $a > PRECISION && $i++ < MAX_ITERATIONS) {
      $guess = ($a + $b) / 2;
      $result = self::BETADIST($guess, $alpha, $beta);
      if ($result == $probability || $result == 0) {
        $b = $a;
      }
      elseif ($result > $probability) {
        $b = $guess;
      }
      else {
        $a = $guess;
      }
    }
    if ($i == MAX_ITERATIONS) {
      return PHPExcel_Calculation_Functions::NA();
    }
    return round($rMin + $guess * ($rMax - $rMin), 12);
  }
  return PHPExcel_Calculation_Functions::VALUE();
}