48 $retVal += $value * $xValue ** (
$key + 1);
83 $equation .=
' + ' . $value .
' * X';
85 $equation .=
'^' . (
$key + 1);
104 foreach ($this->slope as $coefficient) {
105 $coefficients[] = round($coefficient, $dp);
109 return $coefficients;
132 $xx_sum = $xy_sum = $yy_sum = 0;
136 $yy_sum += $yValues[
$i] * $yValues[
$i];
149 for ($j = 0; $j <=
$order; ++$j) {
156 $matrixA =
new Matrix($A);
157 $matrixB =
new Matrix($B);
158 $C = $matrixA->solve($matrixB);
161 for (
$i = 0;
$i < $C->getRowDimension(); ++
$i) {
163 if (abs(
$r) <= 10 ** (-9)) {
166 $coefficients[] =
$r;
169 $this->intersect = array_shift($coefficients);
170 $this->slope = $coefficients;
173 foreach ($this->xValues as $xKey => $xValue) {
190 if ($order < $this->valueCount) {
191 $this->bestFitType .=
'_' .
$order;
calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
getGoodnessOfFit($dp=0)
Return the goodness of fit for this regression.
getEquation($dp=0)
Return the Equation of the best-fit line.
__construct($order, $yValues, $xValues=[])
Define the regression and calculate the goodness of fit for a set of X and Y data values...
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.
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
getOrder()
Return the order of this polynomial.
Class for the creating "special" Matrices.
getSlope($dp=0)
Return the Slope of the line.
polynomialRegression($order, $yValues, $xValues)
Execute the regression and calculate the goodness of fit for a set of X and Y data values...