ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_Best_Fit Class Reference
+ Inheritance diagram for PHPExcel_Best_Fit:
+ Collaboration diagram for PHPExcel_Best_Fit:

Public Member Functions

 getError ()
 
 getBestFitType ()
 
 getValueOfYForX ($xValue)
 Return the Y-Value for a specified value of X. More...
 
 getValueOfXForY ($yValue)
 Return the X-Value for a specified value of Y. More...
 
 getXValues ()
 Return the original set of X-Values. More...
 
 getEquation ($dp=0)
 Return the Equation of the best-fit line. More...
 
 getSlope ($dp=0)
 Return the Slope of the line. More...
 
 getSlopeSE ($dp=0)
 Return the standard error of the Slope. More...
 
 getIntersect ($dp=0)
 Return the Value of X where it intersects Y = 0. More...
 
 getIntersectSE ($dp=0)
 Return the standard error of the Intersect. More...
 
 getGoodnessOfFit ($dp=0)
 Return the goodness of fit for this regression. More...
 
 getGoodnessOfFitPercent ($dp=0)
 
 getStdevOfResiduals ($dp=0)
 Return the standard deviation of the residuals for this regression. More...
 
 getSSRegression ($dp=0)
 
 getSSResiduals ($dp=0)
 
 getDFResiduals ($dp=0)
 
 getF ($dp=0)
 
 getCovariance ($dp=0)
 
 getCorrelation ($dp=0)
 
 getYBestFitValues ()
 
 __construct ($yValues, $xValues=array(), $const=True)
 Define the regression. More...
 

Protected Member Functions

 _calculateGoodnessOfFit ($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
 
 _leastSquareFit ($yValues, $xValues, $const)
 

Protected Attributes

 $_error = False
 
 $_bestFitType = 'undetermined'
 
 $_valueCount = 0
 
 $_xValues = array()
 
 $_yValues = array()
 
 $_adjustToZero = False
 
 $_yBestFitValues = array()
 
 $_goodnessOfFit = 1
 
 $_stdevOfResiduals = 0
 
 $_covariance = 0
 
 $_correlation = 0
 
 $_SSRegression = 0
 
 $_SSResiduals = 0
 
 $_DFResiduals = 0
 
 $_F = 0
 
 $_slope = 0
 
 $_slopeSE = 0
 
 $_intersect = 0
 
 $_intersectSE = 0
 
 $_Xoffset = 0
 
 $_Yoffset = 0
 

Detailed Description

Definition at line 36 of file bestFitClass.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_Best_Fit::__construct (   $yValues,
  $xValues = array(),
  $const = True 
)

Define the regression.

Parameters
float[]$yValues The set of Y-values for this regression
float[]$xValues The set of X-values for this regression
boolean$const

Definition at line 412 of file bestFitClass.php.

References range.

412  {
413  // Calculate number of points
414  $nY = count($yValues);
415  $nX = count($xValues);
416 
417  // Define X Values if necessary
418  if ($nX == 0) {
419  $xValues = range(1,$nY);
420  $nX = $nY;
421  } elseif ($nY != $nX) {
422  // Ensure both arrays of points are the same size
423  $this->_error = True;
424  return False;
425  }
426 
427  $this->_valueCount = $nY;
428  $this->_xValues = $xValues;
429  $this->_yValues = $yValues;
430  } // function __construct()
Resolve range

Member Function Documentation

◆ _calculateGoodnessOfFit()

PHPExcel_Best_Fit::_calculateGoodnessOfFit (   $sumX,
  $sumY,
  $sumX2,
  $sumY2,
  $sumXY,
  $meanX,
  $meanY,
  $const 
)
protected

Definition at line 314 of file bestFitClass.php.

References $_DFResiduals, $_valueCount, and getValueOfYForX().

Referenced by _leastSquareFit(), and PHPExcel_Polynomial_Best_Fit\_polynomial_regression().

314  {
315  $SSres = $SScov = $SScor = $SStot = $SSsex = 0.0;
316  foreach($this->_xValues as $xKey => $xValue) {
317  $bestFitY = $this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
318 
319  $SSres += ($this->_yValues[$xKey] - $bestFitY) * ($this->_yValues[$xKey] - $bestFitY);
320  if ($const) {
321  $SStot += ($this->_yValues[$xKey] - $meanY) * ($this->_yValues[$xKey] - $meanY);
322  } else {
323  $SStot += $this->_yValues[$xKey] * $this->_yValues[$xKey];
324  }
325  $SScov += ($this->_xValues[$xKey] - $meanX) * ($this->_yValues[$xKey] - $meanY);
326  if ($const) {
327  $SSsex += ($this->_xValues[$xKey] - $meanX) * ($this->_xValues[$xKey] - $meanX);
328  } else {
329  $SSsex += $this->_xValues[$xKey] * $this->_xValues[$xKey];
330  }
331  }
332 
333  $this->_SSResiduals = $SSres;
334  $this->_DFResiduals = $this->_valueCount - 1 - $const;
335 
336  if ($this->_DFResiduals == 0.0) {
337  $this->_stdevOfResiduals = 0.0;
338  } else {
339  $this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
340  }
341  if (($SStot == 0.0) || ($SSres == $SStot)) {
342  $this->_goodnessOfFit = 1;
343  } else {
344  $this->_goodnessOfFit = 1 - ($SSres / $SStot);
345  }
346 
347  $this->_SSRegression = $this->_goodnessOfFit * $SStot;
348  $this->_covariance = $SScov / $this->_valueCount;
349  $this->_correlation = ($this->_valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->_valueCount * $sumX2 - pow($sumX,2)) * ($this->_valueCount * $sumY2 - pow($sumY,2)));
350  $this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
351  $this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2));
352  if ($this->_SSResiduals != 0.0) {
353  if ($this->_DFResiduals == 0.0) {
354  $this->_F = 0.0;
355  } else {
356  $this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals);
357  }
358  } else {
359  if ($this->_DFResiduals == 0.0) {
360  $this->_F = 0.0;
361  } else {
362  $this->_F = $this->_SSRegression / $this->_DFResiduals;
363  }
364  }
365  } // function _calculateGoodnessOfFit()
getValueOfYForX($xValue)
Return the Y-Value for a specified value of X.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _leastSquareFit()

PHPExcel_Best_Fit::_leastSquareFit (   $yValues,
  $xValues,
  $const 
)
protected

Definition at line 368 of file bestFitClass.php.

References $_valueCount, $i, and _calculateGoodnessOfFit().

Referenced by PHPExcel_Exponential_Best_Fit\_exponential_regression(), PHPExcel_Linear_Best_Fit\_linear_regression(), PHPExcel_Logarithmic_Best_Fit\_logarithmic_regression(), and PHPExcel_Power_Best_Fit\_power_regression().

368  {
369  // calculate sums
370  $x_sum = array_sum($xValues);
371  $y_sum = array_sum($yValues);
372  $meanX = $x_sum / $this->_valueCount;
373  $meanY = $y_sum / $this->_valueCount;
374  $mBase = $mDivisor = $xx_sum = $xy_sum = $yy_sum = 0.0;
375  for($i = 0; $i < $this->_valueCount; ++$i) {
376  $xy_sum += $xValues[$i] * $yValues[$i];
377  $xx_sum += $xValues[$i] * $xValues[$i];
378  $yy_sum += $yValues[$i] * $yValues[$i];
379 
380  if ($const) {
381  $mBase += ($xValues[$i] - $meanX) * ($yValues[$i] - $meanY);
382  $mDivisor += ($xValues[$i] - $meanX) * ($xValues[$i] - $meanX);
383  } else {
384  $mBase += $xValues[$i] * $yValues[$i];
385  $mDivisor += $xValues[$i] * $xValues[$i];
386  }
387  }
388 
389  // calculate slope
390 // $this->_slope = (($this->_valueCount * $xy_sum) - ($x_sum * $y_sum)) / (($this->_valueCount * $xx_sum) - ($x_sum * $x_sum));
391  $this->_slope = $mBase / $mDivisor;
392 
393  // calculate intersect
394 // $this->_intersect = ($y_sum - ($this->_slope * $x_sum)) / $this->_valueCount;
395  if ($const) {
396  $this->_intersect = $meanY - ($this->_slope * $meanX);
397  } else {
398  $this->_intersect = 0;
399  }
400 
401  $this->_calculateGoodnessOfFit($x_sum,$y_sum,$xx_sum,$yy_sum,$xy_sum,$meanX,$meanY,$const);
402  } // function _leastSquareFit()
_calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBestFitType()

PHPExcel_Best_Fit::getBestFitType ( )

Definition at line 121 of file bestFitClass.php.

References $_bestFitType.

121  {
122  return $this->_bestFitType;
123  } // function getBestFitType()

◆ getCorrelation()

PHPExcel_Best_Fit::getCorrelation (   $dp = 0)

Definition at line 301 of file bestFitClass.php.

References $_correlation.

301  {
302  if ($dp != 0) {
303  return round($this->_correlation,$dp);
304  }
305  return $this->_correlation;
306  } // function getCorrelation()

◆ getCovariance()

PHPExcel_Best_Fit::getCovariance (   $dp = 0)

Definition at line 293 of file bestFitClass.php.

References $_covariance.

293  {
294  if ($dp != 0) {
295  return round($this->_covariance,$dp);
296  }
297  return $this->_covariance;
298  } // function getCovariance()

◆ getDFResiduals()

PHPExcel_Best_Fit::getDFResiduals (   $dp = 0)

Definition at line 277 of file bestFitClass.php.

References $_DFResiduals.

277  {
278  if ($dp != 0) {
279  return round($this->_DFResiduals,$dp);
280  }
281  return $this->_DFResiduals;
282  } // function getDFResiduals()

◆ getEquation()

PHPExcel_Best_Fit::getEquation (   $dp = 0)

Return the Equation of the best-fit line.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 164 of file bestFitClass.php.

164  {
165  return False;
166  } // function getEquation()

◆ getError()

PHPExcel_Best_Fit::getError ( )

Definition at line 116 of file bestFitClass.php.

References $_error.

116  {
117  return $this->_error;
118  } // function getBestFitType()

◆ getF()

PHPExcel_Best_Fit::getF (   $dp = 0)

Definition at line 285 of file bestFitClass.php.

References $_F.

285  {
286  if ($dp != 0) {
287  return round($this->_F,$dp);
288  }
289  return $this->_F;
290  } // function getF()

◆ getGoodnessOfFit()

PHPExcel_Best_Fit::getGoodnessOfFit (   $dp = 0)

Return the goodness of fit for this regression.

Parameters
int$dpNumber of places of decimal precision to return
Returns
float

Definition at line 231 of file bestFitClass.php.

References $_goodnessOfFit.

Referenced by PHPExcel_Polynomial_Best_Fit\__construct().

231  {
232  if ($dp != 0) {
233  return round($this->_goodnessOfFit,$dp);
234  }
235  return $this->_goodnessOfFit;
236  } // function getGoodnessOfFit()
+ Here is the caller graph for this function:

◆ getGoodnessOfFitPercent()

PHPExcel_Best_Fit::getGoodnessOfFitPercent (   $dp = 0)

Definition at line 239 of file bestFitClass.php.

239  {
240  if ($dp != 0) {
241  return round($this->_goodnessOfFit * 100,$dp);
242  }
243  return $this->_goodnessOfFit * 100;
244  } // function getGoodnessOfFitPercent()

◆ getIntersect()

PHPExcel_Best_Fit::getIntersect (   $dp = 0)

Return the Value of X where it intersects Y = 0.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 203 of file bestFitClass.php.

References $_intersect.

Referenced by PHPExcel_Polynomial_Best_Fit\getCoefficients(), PHPExcel_Linear_Best_Fit\getEquation(), PHPExcel_Logarithmic_Best_Fit\getEquation(), PHPExcel_Polynomial_Best_Fit\getEquation(), PHPExcel_Logarithmic_Best_Fit\getValueOfXForY(), PHPExcel_Linear_Best_Fit\getValueOfXForY(), PHPExcel_Polynomial_Best_Fit\getValueOfXForY(), PHPExcel_Logarithmic_Best_Fit\getValueOfYForX(), PHPExcel_Linear_Best_Fit\getValueOfYForX(), and PHPExcel_Polynomial_Best_Fit\getValueOfYForX().

203  {
204  if ($dp != 0) {
205  return round($this->_intersect,$dp);
206  }
207  return $this->_intersect;
208  } // function getIntersect()
+ Here is the caller graph for this function:

◆ getIntersectSE()

PHPExcel_Best_Fit::getIntersectSE (   $dp = 0)

Return the standard error of the Intersect.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 217 of file bestFitClass.php.

References $_intersectSE.

217  {
218  if ($dp != 0) {
219  return round($this->_intersectSE,$dp);
220  }
221  return $this->_intersectSE;
222  } // function getIntersectSE()

◆ getSlope()

PHPExcel_Best_Fit::getSlope (   $dp = 0)

Return the Slope of the line.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 175 of file bestFitClass.php.

References $_slope.

Referenced by PHPExcel_Linear_Best_Fit\getEquation(), PHPExcel_Power_Best_Fit\getEquation(), PHPExcel_Logarithmic_Best_Fit\getEquation(), PHPExcel_Power_Best_Fit\getValueOfXForY(), PHPExcel_Logarithmic_Best_Fit\getValueOfXForY(), PHPExcel_Linear_Best_Fit\getValueOfXForY(), PHPExcel_Power_Best_Fit\getValueOfYForX(), PHPExcel_Linear_Best_Fit\getValueOfYForX(), and PHPExcel_Logarithmic_Best_Fit\getValueOfYForX().

175  {
176  if ($dp != 0) {
177  return round($this->_slope,$dp);
178  }
179  return $this->_slope;
180  } // function getSlope()
+ Here is the caller graph for this function:

◆ getSlopeSE()

PHPExcel_Best_Fit::getSlopeSE (   $dp = 0)

Return the standard error of the Slope.

Parameters
int$dpNumber of places of decimal precision to display
Returns
string

Definition at line 189 of file bestFitClass.php.

References $_slopeSE.

189  {
190  if ($dp != 0) {
191  return round($this->_slopeSE,$dp);
192  }
193  return $this->_slopeSE;
194  } // function getSlopeSE()

◆ getSSRegression()

PHPExcel_Best_Fit::getSSRegression (   $dp = 0)

Definition at line 261 of file bestFitClass.php.

References $_SSRegression.

261  {
262  if ($dp != 0) {
263  return round($this->_SSRegression,$dp);
264  }
265  return $this->_SSRegression;
266  } // function getSSRegression()

◆ getSSResiduals()

PHPExcel_Best_Fit::getSSResiduals (   $dp = 0)

Definition at line 269 of file bestFitClass.php.

References $_SSResiduals.

269  {
270  if ($dp != 0) {
271  return round($this->_SSResiduals,$dp);
272  }
273  return $this->_SSResiduals;
274  } // function getSSResiduals()

◆ getStdevOfResiduals()

PHPExcel_Best_Fit::getStdevOfResiduals (   $dp = 0)

Return the standard deviation of the residuals for this regression.

Parameters
int$dpNumber of places of decimal precision to return
Returns
float

Definition at line 253 of file bestFitClass.php.

References $_stdevOfResiduals.

253  {
254  if ($dp != 0) {
255  return round($this->_stdevOfResiduals,$dp);
256  }
258  } // function getStdevOfResiduals()

◆ getValueOfXForY()

PHPExcel_Best_Fit::getValueOfXForY (   $yValue)

Return the X-Value for a specified value of Y.

Parameters
float$yValueY-Value
Returns
float X-Value

Definition at line 143 of file bestFitClass.php.

143  {
144  return False;
145  } // function getValueOfXForY()

◆ getValueOfYForX()

PHPExcel_Best_Fit::getValueOfYForX (   $xValue)

Return the Y-Value for a specified value of X.

Parameters
float$xValueX-Value
Returns
float Y-Value

Definition at line 132 of file bestFitClass.php.

Referenced by _calculateGoodnessOfFit().

132  {
133  return False;
134  } // function getValueOfYForX()
+ Here is the caller graph for this function:

◆ getXValues()

PHPExcel_Best_Fit::getXValues ( )

Return the original set of X-Values.

Returns
float[] X-Values

Definition at line 153 of file bestFitClass.php.

References $_xValues.

153  {
154  return $this->_xValues;
155  } // function getValueOfXForY()

◆ getYBestFitValues()

PHPExcel_Best_Fit::getYBestFitValues ( )

Definition at line 309 of file bestFitClass.php.

References $_yBestFitValues.

309  {
310  return $this->_yBestFitValues;
311  } // function getYBestFitValues()

Field Documentation

◆ $_adjustToZero

PHPExcel_Best_Fit::$_adjustToZero = False
protected

Definition at line 78 of file bestFitClass.php.

◆ $_bestFitType

PHPExcel_Best_Fit::$_bestFitType = 'undetermined'
protected

Definition at line 50 of file bestFitClass.php.

Referenced by getBestFitType().

◆ $_correlation

PHPExcel_Best_Fit::$_correlation = 0
protected

Definition at line 93 of file bestFitClass.php.

Referenced by getCorrelation().

◆ $_covariance

PHPExcel_Best_Fit::$_covariance = 0
protected

Definition at line 91 of file bestFitClass.php.

Referenced by getCovariance().

◆ $_DFResiduals

PHPExcel_Best_Fit::$_DFResiduals = 0
protected

Definition at line 99 of file bestFitClass.php.

Referenced by _calculateGoodnessOfFit(), and getDFResiduals().

◆ $_error

PHPExcel_Best_Fit::$_error = False
protected

Definition at line 43 of file bestFitClass.php.

Referenced by getError().

◆ $_F

PHPExcel_Best_Fit::$_F = 0
protected

Definition at line 101 of file bestFitClass.php.

Referenced by getF().

◆ $_goodnessOfFit

PHPExcel_Best_Fit::$_goodnessOfFit = 1
protected

Definition at line 87 of file bestFitClass.php.

Referenced by getGoodnessOfFit().

◆ $_intersect

PHPExcel_Best_Fit::$_intersect = 0
protected

Definition at line 107 of file bestFitClass.php.

Referenced by getIntersect().

◆ $_intersectSE

PHPExcel_Best_Fit::$_intersectSE = 0
protected

Definition at line 109 of file bestFitClass.php.

Referenced by getIntersectSE().

◆ $_slope

PHPExcel_Best_Fit::$_slope = 0
protected

Definition at line 103 of file bestFitClass.php.

Referenced by PHPExcel_Polynomial_Best_Fit\getSlope(), and getSlope().

◆ $_slopeSE

PHPExcel_Best_Fit::$_slopeSE = 0
protected

Definition at line 105 of file bestFitClass.php.

Referenced by getSlopeSE().

◆ $_SSRegression

PHPExcel_Best_Fit::$_SSRegression = 0
protected

Definition at line 95 of file bestFitClass.php.

Referenced by getSSRegression().

◆ $_SSResiduals

PHPExcel_Best_Fit::$_SSResiduals = 0
protected

Definition at line 97 of file bestFitClass.php.

Referenced by getSSResiduals().

◆ $_stdevOfResiduals

PHPExcel_Best_Fit::$_stdevOfResiduals = 0
protected

Definition at line 89 of file bestFitClass.php.

Referenced by getStdevOfResiduals().

◆ $_valueCount

PHPExcel_Best_Fit::$_valueCount = 0
protected

◆ $_Xoffset

PHPExcel_Best_Fit::$_Xoffset = 0
protected

Definition at line 111 of file bestFitClass.php.

◆ $_xValues

PHPExcel_Best_Fit::$_xValues = array()
protected

Definition at line 64 of file bestFitClass.php.

Referenced by getXValues().

◆ $_yBestFitValues

PHPExcel_Best_Fit::$_yBestFitValues = array()
protected

Definition at line 85 of file bestFitClass.php.

Referenced by getYBestFitValues().

◆ $_Yoffset

PHPExcel_Best_Fit::$_Yoffset = 0
protected

Definition at line 113 of file bestFitClass.php.

◆ $_yValues

PHPExcel_Best_Fit::$_yValues = array()
protected

Definition at line 71 of file bestFitClass.php.


The documentation for this class was generated from the following file: