ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
LinearBestFit.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class LinearBestFit extends BestFit
6 {
13  protected $bestFitType = 'linear';
14 
22  public function getValueOfYForX($xValue)
23  {
24  return $this->getIntersect() + $this->getSlope() * $xValue;
25  }
26 
34  public function getValueOfXForY($yValue)
35  {
36  return ($yValue - $this->getIntersect()) / $this->getSlope();
37  }
38 
46  public function getEquation($dp = 0)
47  {
48  $slope = $this->getSlope($dp);
49  $intersect = $this->getIntersect($dp);
50 
51  return 'Y = ' . $intersect . ' + ' . $slope . ' * X';
52  }
53 
60  private function linearRegression(array $yValues, array $xValues, bool $const): void
61  {
62  $this->leastSquareFit($yValues, $xValues, $const);
63  }
64 
72  public function __construct($yValues, $xValues = [], $const = true)
73  {
74  parent::__construct($yValues, $xValues);
75 
76  if (!$this->error) {
77  $this->linearRegression($yValues, $xValues, (bool) $const);
78  }
79  }
80 }
linearRegression(array $yValues, array $xValues, bool $const)
Execute the regression and calculate the goodness of fit for a set of X and Y data values...
getEquation($dp=0)
Return the Equation of the best-fit line.
getIntersect($dp=0)
Return the Value of X where it intersects Y = 0.
Definition: BestFit.php:170
getSlope($dp=0)
Return the Slope of the line.
Definition: BestFit.php:138
getValueOfYForX($xValue)
Return the Y-Value for a specified value of X.
getValueOfXForY($yValue)
Return the X-Value for a specified value of Y.
__construct($yValues, $xValues=[], $const =true)
Define the regression and calculate the goodness of fit for a set of X and Y data values...
leastSquareFit(array $yValues, array $xValues, bool $const)
Definition: BestFit.php:405