Hello, so I'm fairly new to python and I have become stumped on this one problem. As much as I would like you to solve the problem for me, I do not want you to do so without explanation, I would much rather have a step by step procedure. After all i'm here to learn python, not to pass a class.
The question is:
Write a program that graphically plots a regression line, that is, the line with the best fit through a collection of points. First ask the user to specify the data points by clicking on them in a graphics window. To find the end of input, place a small rectangle labeled "Done" in the lower left corner of the window; the program will stop gathering points when the user clicks inside that rectangle.
The regression line is the line with the following equation
y = (mean of y values) + m * (x - (mean of x values))
where
(not sure how to write this but)
m = Σxiyi - n(mean of x's) * (mean of y's) / Σxi^2 - n(mean of x's)^2
(I don't think thats written right, I haven't gotten that far in mathematics.)
n = number of points
As the user clicks on points, the program should draw them in the graphics window and keep track of the count of input values and the running sum of x, y, x^2, and xy values. When the user clicks inside the "Done" rectangle, the program then computes value of y (using the equations above) corresponding to the x values at the left and right edges of the window to compute the endpoints of the regression line spanning the window. After the line is drawn, the program will pause for another mouse click before closing the window and quitting.
Okay so heres what i have so far...
from graphics import*
def main():
win=GraphWin("",400, 400)
win.setCoords(-10,-10,10,10)
button=Rectangle(Point(7,-9),Point(10,-10))
button.setFill("Red")
button.draw(win)
done=Text(Point(8.5,-9.5),"Done")
done.setTextColor("Black")
done.draw(win)
point1=win.getMouse()
x=point1.getX()
y=point1.getY()
while x<=7 and y>= -9:
Cir=Circle(p1,.2)
Cir.setFill("Yellow")
Cir.draw(win)
point1=win.getMouse()
x=point1.getX()
y=point1.getY()
I have the GUI drawn up, I have my little rectangle box that says DONE, and whenever i click on the GUI, little circles draw up signifying points. Not exactly sure how go on to the next step, any help would be greatly appreciated!