You are here

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

* LOGEST * * Calculates an exponential curve that best fits the X and Y data series, * and then returns an array that describes the line. * *

Parameters

array of mixed Data Series Y: * @param array of mixed Data Series X * @param boolean A logical value specifying whether to force the intersect to equal 0. * @param boolean A logical value specifying whether to return additional regression statistics. * @return array

File

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

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function LOGEST($yValues, $xValues = null, $const = True, $stats = False) {
  $const = is_null($const) ? True : (bool) PHPExcel_Calculation_Functions::flattenSingleValue($const);
  $stats = is_null($stats) ? False : (bool) PHPExcel_Calculation_Functions::flattenSingleValue($stats);
  if (is_null($xValues)) {
    $xValues = range(1, count(PHPExcel_Calculation_Functions::flattenArray($yValues)));
  }
  if (!self::_checkTrendArrays($yValues, $xValues)) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $yValueCount = count($yValues);
  $xValueCount = count($xValues);
  foreach ($yValues as $value) {
    if ($value <= 0.0) {
      return PHPExcel_Calculation_Functions::NaN();
    }
  }
  if ($yValueCount == 0 || $yValueCount != $xValueCount) {
    return PHPExcel_Calculation_Functions::NA();
  }
  elseif ($yValueCount == 1) {
    return 1;
  }
  $bestFitExponential = trendClass::calculate(trendClass::TREND_EXPONENTIAL, $yValues, $xValues, $const);
  if ($stats) {
    return array(
      array(
        $bestFitExponential
          ->getSlope(),
        $bestFitExponential
          ->getSlopeSE(),
        $bestFitExponential
          ->getGoodnessOfFit(),
        $bestFitExponential
          ->getF(),
        $bestFitExponential
          ->getSSRegression(),
      ),
      array(
        $bestFitExponential
          ->getIntersect(),
        $bestFitExponential
          ->getIntersectSE(),
        $bestFitExponential
          ->getStdevOfResiduals(),
        $bestFitExponential
          ->getDFResiduals(),
        $bestFitExponential
          ->getSSResiduals(),
      ),
    );
  }
  else {
    return array(
      $bestFitExponential
        ->getSlope(),
      $bestFitExponential
        ->getIntersect(),
    );
  }
}