You are here

protected function PHPExcel_Best_Fit::_calculateGoodnessOfFit in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/trend/bestFitClass.php \PHPExcel_Best_Fit::_calculateGoodnessOfFit()
2 calls to PHPExcel_Best_Fit::_calculateGoodnessOfFit()
PHPExcel_Best_Fit::_leastSquareFit in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/trend/bestFitClass.php
PHPExcel_Polynomial_Best_Fit::_polynomial_regression in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/trend/polynomialBestFitClass.php
* Execute the regression and calculate the goodness of fit for a set of X and Y data values * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/trend/bestFitClass.php, line 314

Class

PHPExcel_Best_Fit
PHPExcel_Best_Fit

Code

protected function _calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const) {
  $SSres = $SScov = $SScor = $SStot = $SSsex = 0.0;
  foreach ($this->_xValues as $xKey => $xValue) {
    $bestFitY = $this->_yBestFitValues[$xKey] = $this
      ->getValueOfYForX($xValue);
    $SSres += ($this->_yValues[$xKey] - $bestFitY) * ($this->_yValues[$xKey] - $bestFitY);
    if ($const) {
      $SStot += ($this->_yValues[$xKey] - $meanY) * ($this->_yValues[$xKey] - $meanY);
    }
    else {
      $SStot += $this->_yValues[$xKey] * $this->_yValues[$xKey];
    }
    $SScov += ($this->_xValues[$xKey] - $meanX) * ($this->_yValues[$xKey] - $meanY);
    if ($const) {
      $SSsex += ($this->_xValues[$xKey] - $meanX) * ($this->_xValues[$xKey] - $meanX);
    }
    else {
      $SSsex += $this->_xValues[$xKey] * $this->_xValues[$xKey];
    }
  }
  $this->_SSResiduals = $SSres;
  $this->_DFResiduals = $this->_valueCount - 1 - $const;
  if ($this->_DFResiduals == 0.0) {
    $this->_stdevOfResiduals = 0.0;
  }
  else {
    $this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
  }
  if ($SStot == 0.0 || $SSres == $SStot) {
    $this->_goodnessOfFit = 1;
  }
  else {
    $this->_goodnessOfFit = 1 - $SSres / $SStot;
  }
  $this->_SSRegression = $this->_goodnessOfFit * $SStot;
  $this->_covariance = $SScov / $this->_valueCount;
  $this->_correlation = ($this->_valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->_valueCount * $sumX2 - pow($sumX, 2)) * ($this->_valueCount * $sumY2 - pow($sumY, 2)));
  $this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
  $this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - $sumX * $sumX / $sumX2));
  if ($this->_SSResiduals != 0.0) {
    if ($this->_DFResiduals == 0.0) {
      $this->_F = 0.0;
    }
    else {
      $this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals);
    }
  }
  else {
    if ($this->_DFResiduals == 0.0) {
      $this->_F = 0.0;
    }
    else {
      $this->_F = $this->_SSRegression / $this->_DFResiduals;
    }
  }
}