177 return round($this->_slope,$dp);
191 return round($this->_slopeSE,$dp);
205 return round($this->_intersect,$dp);
219 return round($this->_intersectSE,$dp);
233 return round($this->_goodnessOfFit,$dp);
241 return round($this->_goodnessOfFit * 100,$dp);
243 return $this->_goodnessOfFit * 100;
255 return round($this->_stdevOfResiduals,$dp);
263 return round($this->_SSRegression,$dp);
271 return round($this->_SSResiduals,$dp);
279 return round($this->_DFResiduals,$dp);
287 return round($this->_F,$dp);
295 return round($this->_covariance,$dp);
303 return round($this->_correlation,$dp);
315 $SSres = $SScov = $SScor = $SStot = $SSsex = 0.0;
316 foreach($this->_xValues as $xKey => $xValue) {
317 $bestFitY = $this->_yBestFitValues[$xKey] = $this->
getValueOfYForX($xValue);
319 $SSres += ($this->_yValues[$xKey] - $bestFitY) * ($this->_yValues[$xKey] - $bestFitY);
321 $SStot += ($this->_yValues[$xKey] - $meanY) * ($this->_yValues[$xKey] - $meanY);
323 $SStot += $this->_yValues[$xKey] * $this->_yValues[$xKey];
325 $SScov += ($this->_xValues[$xKey] - $meanX) * ($this->_yValues[$xKey] - $meanY);
327 $SSsex += ($this->_xValues[$xKey] - $meanX) * ($this->_xValues[$xKey] - $meanX);
329 $SSsex += $this->_xValues[$xKey] * $this->_xValues[$xKey];
333 $this->_SSResiduals = $SSres;
334 $this->_DFResiduals = $this->_valueCount - 1 - $const;
336 if ($this->_DFResiduals == 0.0) {
337 $this->_stdevOfResiduals = 0.0;
339 $this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
341 if (($SStot == 0.0) || ($SSres == $SStot)) {
342 $this->_goodnessOfFit = 1;
344 $this->_goodnessOfFit = 1 - ($SSres / $SStot);
347 $this->_SSRegression = $this->_goodnessOfFit * $SStot;
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) {
359 if ($this->_DFResiduals == 0.0) {
370 $x_sum = array_sum($xValues);
371 $y_sum = array_sum($yValues);
374 $mBase = $mDivisor = $xx_sum = $xy_sum = $yy_sum = 0.0;
376 $xy_sum += $xValues[
$i] * $yValues[
$i];
377 $xx_sum += $xValues[
$i] * $xValues[
$i];
378 $yy_sum += $yValues[
$i] * $yValues[
$i];
381 $mBase += ($xValues[
$i] - $meanX) * ($yValues[
$i] - $meanY);
382 $mDivisor += ($xValues[
$i] - $meanX) * ($xValues[
$i] - $meanX);
384 $mBase += $xValues[
$i] * $yValues[
$i];
385 $mDivisor += $xValues[
$i] * $xValues[
$i];
391 $this->_slope = $mBase / $mDivisor;
396 $this->_intersect = $meanY - ($this->_slope * $meanX);
398 $this->_intersect = 0;
414 $nY = count($yValues);
415 $nX = count($xValues);
419 $xValues =
range(1,$nY);
421 } elseif ($nY != $nX) {
423 $this->_error = True;
427 $this->_valueCount = $nY;
428 $this->_xValues = $xValues;
429 $this->_yValues = $yValues;
getXValues()
Return the original set of X-Values.
getGoodnessOfFitPercent($dp=0)
getSlopeSE($dp=0)
Return the standard error of the Slope.
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
getValueOfYForX($xValue)
Return the Y-Value for a specified value of X.
getIntersectSE($dp=0)
Return the standard error of the Intersect.
getEquation($dp=0)
Return the Equation of the best-fit line.
getStdevOfResiduals($dp=0)
Return the standard deviation of the residuals for this regression.
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
_calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
getGoodnessOfFit($dp=0)
Return the goodness of fit for this regression.
getSlope($dp=0)
Return the Slope of the line.
Create styles array
The data for the language used.
__construct($yValues, $xValues=array(), $const=True)
Define the regression.
_leastSquareFit($yValues, $xValues, $const)