Chapter 8: Problem 13
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=\bar{y}+m(x-\bar{x}) \\] where \\[ m=\frac{\sum x_{i} y_{i}-n \bar{x} \bar{y}}{\sum x_{i}^{2}-n \bar{x}^{2}} \\] \(\bar{x}\) is the mean of the \(x\) -values, \(\bar{y}\) is the mean of the \(y\) -values, and \(n\) is the 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 \(x y\) values. When the user clicks inside the "Done" rectangle, the program then computes the 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.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.