5 * Copyright (c) 2006 - 2014 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @package PHPExcel_Shared_Trend
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 require_once(PHPEXCEL_ROOT
. 'PHPExcel/Shared/trend/bestFitClass.php');
33 * PHPExcel_Linear_Best_Fit
36 * @package PHPExcel_Shared_Trend
37 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
39 class PHPExcel_Linear_Best_Fit
extends PHPExcel_Best_Fit
42 * Algorithm type to use for best-fit
43 * (Name of this trend class)
47 protected $_bestFitType = 'linear';
51 * Return the Y-Value for a specified value of X
53 * @param float $xValue X-Value
54 * @return float Y-Value
56 public function getValueOfYForX($xValue) {
57 return $this->getIntersect() +
$this->getSlope() * $xValue;
58 } // function getValueOfYForX()
62 * Return the X-Value for a specified value of Y
64 * @param float $yValue Y-Value
65 * @return float X-Value
67 public function getValueOfXForY($yValue) {
68 return ($yValue - $this->getIntersect()) / $this->getSlope();
69 } // function getValueOfXForY()
73 * Return the Equation of the best-fit line
75 * @param int $dp Number of places of decimal precision to display
78 public function getEquation($dp=0) {
79 $slope = $this->getSlope($dp);
80 $intersect = $this->getIntersect($dp);
82 return 'Y = '.$intersect.' + '.$slope.' * X';
83 } // function getEquation()
87 * Execute the regression and calculate the goodness of fit for a set of X and Y data values
89 * @param float[] $yValues The set of Y-values for this regression
90 * @param float[] $xValues The set of X-values for this regression
91 * @param boolean $const
93 private function _linear_regression($yValues, $xValues, $const) {
94 $this->_leastSquareFit($yValues, $xValues,$const);
95 } // function _linear_regression()
99 * Define the regression and calculate the goodness of fit for a set of X and Y data values
101 * @param float[] $yValues The set of Y-values for this regression
102 * @param float[] $xValues The set of X-values for this regression
103 * @param boolean $const
105 function __construct($yValues, $xValues=array(), $const=True) {
106 if (parent
::__construct($yValues, $xValues) !== False) {
107 $this->_linear_regression($yValues, $xValues, $const);
109 } // function __construct()
111 } // class linearBestFit