points); for ($i = 0; $i < $n; $i++) { for ($j = $i + 1; $j < $n; $j++) { $pointi = $this->points[$i]; $pointj = $this->points[$j]; if ($pointj[0] != $pointi[0]) { $slopes[] = ($pointj[1] - $pointi[1]) / ($pointj[0] - $pointi[0]); } } } $this->m = Average::median($slopes); $this->b = Average::median($this->ys) - ($this->m * Average::median($this->xs)); $this->parameters = [$this->b, $this->m]; } /** * Evaluate the regression equation at x * Uses the instance model's evaluateModel method. * * @param float $x * * @return float */ public function evaluate(float $x): float { return $this->evaluateModel($x, $this->parameters); } }