AP subjects/AP Statistics/Least-Squares Regression Line Simulator
CED 5.5AP Statistics

Least-Squares Regression Line Simulator

Use this free least-squares regression line simulator to drag points on a scatterplot and watch the line, the residuals and r2r^2 refit at once. It shows why it is called the least-squares line: of all possible lines, it makes the sum of squared residuals smallest.

How to use the simulator

There are no sliders. Four preset buttons load data: Tight, Moderate and Weak (12 points each) and Outlier (10 points). Tight is loaded when the page opens.
To move a point, press within about 20 pixels of it and drag. The point turns gold while you hold it, and both coordinates stay between 0.1 and 9.9 on axes that run from 0 to 10.
  • Scatterplot. The navy line is the least-squares regression line (LSRL). Each point has a dashed vertical segment to the line: teal for a positive residual (point above the line) and coral for a negative one. A small gold dot marks (x̄, ȳ).
  • Residual plot. Below the scatterplot, each residual is plotted against x around a zero line. Its vertical scale resizes automatically, so read it for pattern rather than size.
  • Readouts. The equation ŷ = b0 + b1x to two decimals, then Slope b1, Intercept b0 and r2 to three decimals, and SSR Σe2, the sum of squared residuals, to two decimals. r2 is shown as a decimal, so 0.841 means 84.1%.

The formula

The AP formula sheet writes the line as y^=a+bx\hat{y} = a + bx; the simulator calls the intercept b0b_0 and the slope b1b_1.
b=r sysxa=yˉ−bxˉb = r\,\frac{s_y}{s_x} \qquad a = \bar{y} - b\bar{x}
residual=y−y^\text{residual} = y - \hat{y}
  • The LSRL is the one line that minimizes ∑(y−y^)2\sum (y - \hat{y})^2.
  • It always passes through (xˉ,yˉ)(\bar{x}, \bar{y}), which is why the gold dot sits on the line however you drag.
  • The residuals always add to 0.
  • The slope is the predicted change in y for a one-unit increase in x. The intercept is the predicted y when x = 0, which only means something if x = 0 is reasonable for the data.
  • r2r^2 is the proportion of variation in y accounted for by the linear model.

Worked example

Problem: The Moderate preset has 12 points with x̄ = 5.4333, sx = 2.9586, ȳ = 5.2833, sy = 2.0126 and r = 0.9169. Find the LSRL, interpret the slope and r2, and find the residual for the point (5.1, 4.1).
Step 1: Slope. b=0.9169×2.01262.9586=0.6237b = 0.9169 \times \dfrac{2.0126}{2.9586} = 0.6237.
Step 2: Intercept. a=5.2833−0.6237(5.4333)=1.894a = 5.2833 - 0.6237(5.4333) = 1.894. The line is y^=1.894+0.624x\hat{y} = 1.894 + 0.624x.
Step 3: Interpret. For each increase of 1 in x, the predicted y increases by about 0.624. Since r2 = 0.91692 = 0.841, about 84.1% of the variation in y is accounted for by the linear model with x.
Step 4: Residual. At x=5.1x = 5.1, y^=1.894+0.6237(5.1)=5.075\hat{y} = 1.894 + 0.6237(5.1) = 5.075. The residual is 4.1−5.075=−0.9754.1 - 5.075 = -0.975: the point is 0.975 below the line, so the model overpredicts it.
Check it in the simulator: press Moderate. The equation reads ŷ = 1.89 + 0.62x, with b1 = 0.624, b0 = 1.894, r2 = 0.841 and SSR = 7.10. The point at x = 5.1 has a coral segment.
Extension with the Outlier preset: nine points lie almost on a line and one sits far below at (5, 0.5). The readout shows ŷ = 0.83 + 0.86x, r2 = 0.651 and SSR = 23.73. Drag that point up to about y = 5.6, into the pattern. The slope stays 0.858, the intercept rises to about 1.34, r2 goes to almost 1 and SSR falls close to 0. The outlier sits at x = 5, which is x̄, so it pulls the whole line down without tilting it. Drag an end point such as (9, 9) instead and the slope changes a lot, because points far from x̄ have more leverage.

Common mistakes on the AP exam

  • Reversing the residual. Residual = actual − predicted (y − ŷ). A negative residual means the line overpredicted.
  • Interpreting the slope as certain. Say "the predicted y increases by 0.624 for each 1-unit increase in x", and use the variable names from the problem.
  • Extrapolating. Predictions far outside the range of the x data are unreliable, and that includes the intercept when x = 0 is far from the data.
  • Trusting r2 alone. A high r2 does not show that a line is the right model. A curved pattern in the residual plot means a linear model is not appropriate.
  • Treating every outlier as influential. An influential point is one whose removal changes the slope or intercept noticeably. A point with an extreme x value has high leverage; an outlier near x̄ may change r2 a lot but barely move the slope.
  • Swapping x and y. Regressing y on x does not give the same line as regressing x on y. Predict the response from the explanatory variable.

When the AP exam uses this

This is topic 5.5, Least-Squares Regression, in Unit 5 (Regression Analysis). Expect to write the equation from summary statistics or computer output, interpret the slope, intercept and r2 in context, compute and interpret a residual, and judge a residual plot. Questions often give regression output from software and ask you to read the coefficients off it.
Embed this simulator on your class page

Free for classroom use. Paste this into your site, LMS page or blog; keep the credit link under it.