public function leastSquares(array $ys, array $xs, $order = 1, $fit_constant = 1) : Matrix
{
$this->reg_ys = $ys;
$this->reg_xs = $xs;
$this->fit_constant = $fit_constant;
$this->p = $order;
$this->ν = $this->n - $this->p - $this->fit_constant;
// y = Xa
$X = $this->createDesignMatrix($xs);
$y = new ColumnVector($ys);
// a = (XᵀX)⁻¹Xᵀy
$Xᵀ = $X->transpose();
$this->⟮XᵀX⟯⁻¹ = $Xᵀ->multiply($X)->inverse();
$temp_matrix = $this->⟮XᵀX⟯⁻¹->multiply($Xᵀ);
$this->reg_P = $X->multiply($temp_matrix);
$β_hat = $temp_matrix->multiply($y);
$this->reg_Yhat = $X->multiply($β_hat)->getColumn(0);
return $β_hat;
}