This free linear regression calculator finds the least-squares regression line ŷ = a + bx, the correlation r and r² from your x, y data, and draws a scatterplot, a residual plot and a residual table, with AP-style interpretations, for statistics and AP® Statistics students.
Loading the linear regression calculator…
How to use the linear regression calculator
- Enter your data. Paste one x, y pair per line (like 1, 62), “(x, y)” pairs, or two columns copied from a spreadsheet. Or switch to Two lists and enter the x and y values separately.
- Name the variables (optional), like “hours studied” and “test score”, so the interpretations are written in context.
- Add an x to predict at (optional) to get ŷ for that x. The calculator warns you when it’s extrapolation.
- Read the results. You get the equation, r and r², the scatterplot with the line, the residual plot, sentences interpreting the slope, intercept, r, r² and s, the steps and a residual table.
Worked example
Eight students recorded how many hours they studied for a test and their scores:
| Hours (x) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Score (y) | 62 | 66 | 71 | 70 | 78 | 81 | 84 | 88 |
- Summarize. x̄ = 4.5, ȳ = 75, sₓ = 2.449, s_y = 9.150 and r = 0.988.
- Find the slope. b = r(s_y ÷ sₓ) = 0.988 × (9.150 ÷ 2.449) = 3.6905.
- Find the intercept. a = ȳ − b·x̄ = 75 − 3.6905 × 4.5 = 58.3929.
- Write the line. ŷ = 58.3929 + 3.6905x, or predicted score = 58.39 + 3.69(hours studied).
- Predict. For 5.5 hours, ŷ = 58.3929 + 3.6905 × 5.5 = 78.69 points.
Interpretations: For each additional hour studied, the predicted test score increases by about 3.69 points. r² = 0.976, so about 97.6% of the variation in test scores is accounted for by the linear model relating score to hours studied. The student who studied 4 hours scored 70, below the predicted 73.15, a residual of 70 − 73.15 = −3.15 points.
What the least-squares regression line is
For any line through a scatterplot, each point has a residual, the vertical distance from the point to the line: residual = y − ŷ. The least-squares regression line (LSRL) is the one line that makes the sum of the squared residuals as small as possible. Squaring keeps positive and negative residuals from cancelling and gives large misses more weight.
The LSRL has a few properties that are worth knowing for the exam:
- It always passes through the point (x̄, ȳ).
- Its residuals always add up to 0.
- Its slope has the same sign as r.
- Swapping x and y gives a different line, so the choice of explanatory variable matters.
The formulas
| Quantity | Formula | Meaning |
|---|---|---|
| Slope | b = r · (s_y ÷ sₓ) | Predicted change in y for each increase of 1 in x |
| y-intercept | a = ȳ − b·x̄ | Predicted y when x = 0 |
| Correlation | r = Σ(zₓ · z_y) ÷ (n − 1) | Direction and strength of the linear association |
| Coefficient of determination | r² | Fraction of the variation in y accounted for by the model |
| Standard deviation of residuals | s = √(Σ(y − ŷ)² ÷ (n − 2)) | Typical size of a prediction error |
The AP® Statistics formula sheet gives the slope as b = r(s_y/sₓ) and the intercept as a = ȳ − b·x̄, which is the route the calculator’s steps follow.
Correlation: r
The correlation coefficient r runs from −1 to 1. Its sign gives the direction (positive: y tends to rise as x rises), and its size gives the strength of the linear relationship: values near ±1 are strong, values near 0 are weak. A few cautions:
- r only measures linear association. A strong curved pattern can have an r near 0.
- r has no units and doesn’t change if you swap x and y or change units (like inches to centimeters).
- r is not resistant: one outlier can raise or lower it a lot.
- Correlation is not causation. A strong r between two variables doesn’t show that one causes the other.
Interpreting slope, intercept, r² and s
AP® Statistics questions expect interpretations in context, written as predictions:
- Slope: “For each additional [x unit] of [x], the predicted [y] increases (or decreases) by about [b] [y units].” Use “predicted” because the line describes an average trend.
- y-intercept: “When [x] = 0, the predicted [y] is [a].” If x = 0 is far outside the data, say the intercept has no practical meaning.
- r²: “About [r² as a percent] of the variation in [y] is accounted for by the linear model relating [y] to [x].”
- s: “The actual [y] values typically differ from the values predicted by the line by about [s] [y units].”
Type the variable names in the calculator and it fills these in for you.
Residuals and the residual plot
A residual plot graphs each residual against x (or against ŷ). It’s the best check of whether a line is a good model:
- Random scatter around 0: a linear model is appropriate.
- A curve (residuals positive at both ends and negative in the middle, or the reverse): the relationship isn’t linear, so try a transformation or a nonlinear model.
- A fan shape (residuals spreading out as x grows): predictions are less reliable for some x values.
Points with unusually large residuals are possible outliers; the calculator highlights any residual more than 2s from 0. A point far from the others in the x direction can be influential, pulling the line toward itself, even when its residual is small.
Predictions and extrapolation
To predict y, substitute an x value into the equation. Predictions are most trustworthy for x values inside the range of the data. Using the line far outside that range is extrapolation: the pattern may not continue, so the prediction can be badly wrong. A study-time line fit to 1–8 hours, for example, predicts a score above 100 for 12 hours.
Reading computer regression output
AP questions often give software output instead of raw data. It usually looks like this for the study-time example:
| Predictor | Coef |
|---|---|
| Constant | 58.3929 |
| Hours | 3.6905 |
with S = 1.5262 and R-Sq = 97.6% listed underneath. The “Constant” coefficient is the intercept a, the coefficient next to the explanatory variable is the slope b, S is the standard deviation of the residuals s, and R-Sq is r² as a percent. To find r, take the square root of r² and give it the sign of the slope. The calculator reports the same four numbers, so you can practice matching them up.
Regression on the AP® Statistics exam
Least-squares regression is part of AP® Statistics Unit 2, Exploring Two-Variable Data, and slope inference returns in Unit 9. Expect to read computer regression output, interpret the slope, intercept, r² and s in context, judge a residual plot and calculate a residual. For more practice, read Least Squares Regression, Residuals and Correlation, and browse the AP® Statistics cheat sheets. After a practice test, estimate your score with the AP® Statistics Score Calculator.
FAQ
How do you find the least-squares regression line?
Find the means and standard deviations of x and y and the correlation r. The slope is b = r(s_y/sₓ) and the intercept is a = ȳ − b·x̄, so the line is ŷ = a + bx. For (1, 1), (2, 3) and (3, 2), r = 0.5, sₓ = s_y = 1, so b = 0.5 and a = 2 − 0.5 × 2 = 1: ŷ = 1 + 0.5x.
How do I interpret the slope?
The slope is the predicted change in y for each increase of 1 in x. Say it in context and as a prediction: “For each additional hour studied, the predicted test score increases by about 3.69 points.” Avoid saying y “will” change by that amount: the line describes an average trend, not a guarantee for each individual.
What is the difference between r and r²?
r measures the direction and strength of a linear association, from −1 to 1. r² is the fraction of the variation in y that the linear model with x accounts for. With r = 0.5, r² = 0.25: about 25% of the variation in y is accounted for by the linear model relating y to x.
What is a residual?
A residual is the actual y minus the predicted y: e = y − ŷ. A positive residual means the point is above the line, and a negative one means it’s below. The least-squares line makes the sum of the squared residuals as small as possible, and the residuals always add up to 0.
How do I know if a linear model is appropriate?
Look at the residual plot. Random scatter around 0 with no curve and no fan shape suggests a line is a good model. A curved pattern means a nonlinear model would fit better, and a fan shape means the predictions are less reliable for some x values. A high r alone doesn’t prove the relationship is linear.
What is extrapolation?
Extrapolation is using the line to predict y for an x value outside the range of the data. The pattern may not continue beyond the data, so those predictions can be badly wrong. The calculator flags a prediction as extrapolation when x is below the smallest or above the largest x in your data.