MathPHP\Statistics\Regression\TheilSen::calculate PHP Méthode

calculate() public méthode

Procedure: Calculate the slopes of all pairs of points and select the median value Calculate the intercept using the slope, and the medians of the X and Y values. b = Ymedian - (m * Xmedian)
public calculate ( )
    public function calculate()
    {
        // The slopes array will be a list of slopes between all pairs of points
        $slopes = [];
        $n = count($this->points);
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i + 1; $j < $n; $j++) {
                $pointi = $this->points[$i];
                $pointj = $this->points[$j];
                $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];
    }
TheilSen