You are here

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

* LINEST * * Calculates the statistics for a line by using the "least squares" method to calculate a straight line that best fits your data, * 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 1960

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function LINEST($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);
  if ($yValueCount == 0 || $yValueCount != $xValueCount) {
    return PHPExcel_Calculation_Functions::NA();
  }
  elseif ($yValueCount == 1) {
    return 0;
  }
  $bestFitLinear = trendClass::calculate(trendClass::TREND_LINEAR, $yValues, $xValues, $const);
  if ($stats) {
    return array(
      array(
        $bestFitLinear
          ->getSlope(),
        $bestFitLinear
          ->getSlopeSE(),
        $bestFitLinear
          ->getGoodnessOfFit(),
        $bestFitLinear
          ->getF(),
        $bestFitLinear
          ->getSSRegression(),
      ),
      array(
        $bestFitLinear
          ->getIntersect(),
        $bestFitLinear
          ->getIntersectSE(),
        $bestFitLinear
          ->getStdevOfResiduals(),
        $bestFitLinear
          ->getDFResiduals(),
        $bestFitLinear
          ->getSSResiduals(),
      ),
    );
  }
  else {
    return array(
      $bestFitLinear
        ->getSlope(),
      $bestFitLinear
        ->getIntersect(),
    );
  }
}