/** * Esta función no está adaptada a bcmath pues se supone que los datos provenientes de la regresión tiene unos * valores aceptables dentro de los rangos de valores de las variables de PHP * * @param $image * @param int $colorPoints * @param int $colorLine * @param int $colorFormula * @param int $x * @param int $y * @param int $x1 * @param int $y1 * @param MatrixBase $matrixX * @param MatrixBase $matrixY */ private function drawDotPlot($image, $colorPoints, $colorLine, $colorFormula, $x, $y, $x1, $y1, MatrixBase $matrixX, MatrixBase $matrixY) { $width = $x1 - $x; $height = $y1 - $y; $arrayX = $matrixX->getArray(); $minX = min($arrayX[1]); $maxX = max($arrayX[1]); $arrayY = $matrixY->getArray(); $minY = min($arrayY[1]); $maxY = max($arrayY[1]); $data = $this->regressionSimple($matrixX, $matrixY); $minY = min($minY, $data['B0'] + $data['B1'] * $minX); $minY = min($minY, $data['B0'] + $data['B1'] * $maxX); $maxY = max($maxY, $data['B0'] + $data['B1'] * $minX); $maxY = max($maxY, $data['B0'] + $data['B1'] * $maxX); $factorX = $width / abs($maxX - $minX); $factorY = $height / abs($maxY - $minY); for ($abscisas = 1; $abscisas <= $matrixX->getNumCols(); $abscisas++) { $posX = $x + ($arrayX[1][$abscisas] - $minX) * $factorX; $posY = $y1 - ($arrayY[1][$abscisas] - $minY) * $factorY; imagesetpixel($image, $posX, $posY, $colorPoints); imagesetpixel($image, $posX + 1, $posY, $colorPoints); imagesetpixel($image, $posX, $posY + 1, $colorPoints); imagesetpixel($image, $posX + 1, $posY + 1, $colorPoints); } $posX1 = $x + ($minX - $minX) * $factorX; $posY1 = $y1 - ($data['B0'] + $data['B1'] * $minX - $minY) * $factorY; $posX2 = $x + ($maxX - $minX) * $factorX; $posY2 = $y1 - ($data['B0'] + $data['B1'] * $maxX - $minY) * $factorY; imageline($image, $posX1, $posY1, $posX2, $posY2, $colorLine); $this->imageTextCentered($image, $colorFormula, 0, $this->fontSize / 3, $this->fontName, $x, $y, $x1, $y1, 'y=' . round($data['B0'], 3) . '+' . round($data['B1'], 3) . "x\nR2=" . round($data['r2'], 3)); }