29 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/bestFitClass.php';
30 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/JAMA/Matrix.php';
78 foreach($slope as $key => $value) {
80 $retVal += $value * pow($xValue, $key + 1);
108 $equation =
'Y = '.$intersect;
109 foreach($slope as $key => $value) {
111 $equation .=
' + '.$value.
' * X';
113 $equation .=
'^'.($key + 1);
129 $coefficients =
array();
130 foreach($this->_slope as $coefficient) {
131 $coefficients[] = round($coefficient,$dp);
133 return $coefficients;
154 $x_sum = array_sum($xValues);
155 $y_sum = array_sum($yValues);
156 $xx_sum = $xy_sum = 0;
158 $xy_sum += $xValues[$i] * $yValues[$i];
159 $xx_sum += $xValues[$i] * $xValues[$i];
160 $yy_sum += $yValues[$i] * $yValues[$i];
171 for ($j = 0; $j <= $order; ++$j) {
172 $A[$i][$j] = pow($xValues[$i], $j);
176 $B[$i] =
array($yValues[$i]);
178 $matrixA =
new Matrix($A);
179 $matrixB =
new Matrix($B);
180 $C = $matrixA->solve($matrixB);
182 $coefficients =
array();
183 for($i = 0; $i < $C->m; ++$i) {
185 if (abs(
$r) <= pow(10, -9)) {
188 $coefficients[] =
$r;
191 $this->_intersect = array_shift($coefficients);
192 $this->_slope = $coefficients;
195 foreach($this->_xValues as $xKey => $xValue) {
210 if (parent::__construct($yValues, $xValues) !== False) {
211 if ($order < $this->_valueCount) {
212 $this->_bestFitType .=
'_'.$order;
213 $this->_order = $order;
216 $this->_error = True;
219 $this->_error = True;
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
getOrder()
Return the order of this polynomial.
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.
_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.
_polynomial_regression($order, $yValues, $xValues, $const)
Execute the regression and calculate the goodness of fit for a set of X and Y data values...
Create styles array
The data for the language used.
getSlope($dp=0)
Return the Slope of the line.
__construct($order, $yValues, $xValues=array(), $const=True)
Define the regression and calculate the goodness of fit for a set of X and Y data values...