Linear regression calculator (r, r-squared, line)
By Jude Wallis · Published
A correlation and regression calculator takes your x,y pairs and returns the correlation coefficient r, r-squared, and the least-squares line y-hat = a + bx, plus each residual. Enter the pairs, then read r, the line, and how far each observed value sits from its prediction.
least-squares regression line
y-hat = 1.3 + 0.9x
r = 0.9, r² = 0.81: about 81% of the variation in y is explained by the linear relationship with x.
| x | y | predicted | residual |
|---|---|---|---|
| 1 | 2 | 2.2 | -0.2 |
| 2 | 3 | 3.1 | -0.1 |
| 3 | 5 | 4 | 1 |
| 4 | 4 | 4.9 | -0.9 |
| 5 | 6 | 5.8 | 0.2 |
Steps
- 1.n = 5; x-bar = 3, y-bar = 4
- 2.sx = 1.5811, sy = 1.5811, r = 0.9
- 3.slope b = r(sy/sx) = 0.9 x (1.5811/1.5811) = 0.9
- 4.intercept a = y-bar - b(x-bar) = 4 - 0.9 x 3 = 1.3
AP Statistics: Unit 5 (topics 5.2 Correlation, 5.3 Linear Regression Models, 5.4 Residuals, 5.5 Least-Squares Regression). This calculator supports Fall 2026 Unit 5 (topics 5.2 to 5.5), where you use technology to find r, r-squared, and the least-squares line and then interpret them in context, while inference for the regression slope is not part of the Fall 2026 exam.
What the linear regression calculator gives you
This linear regression calculator and correlation coefficient calculator work on the same input: a list of paired values, one and one for each observation. Here is the explanatory variable (the predictor) and is the response variable (what you want to predict).
From your pairs the tool returns four things. The correlation coefficient measures the strength and direction of the linear association. The coefficient of determination (r-squared) is the proportion of the variation in explained by the linear relationship with .
The least-squares line is the best-fit line, where (read "y-hat") is the predicted response, is the y-intercept, and is the slope. Finally, the residual for each point is how far the observed sits above or below the line.
The correlation coefficient is always between and , inclusive, and it is unit-free, so changing units does not change it.
The formulas behind r, the line, and residuals
Start with the means. Write ("x-bar") for the mean of the values and ("y-bar") for the mean of the values. Write and for the sample standard deviations of and , each computed with in the denominator.
The correlation coefficient uses the paired deviations from the means:
The slope and intercept of the least-squares line follow from and the spreads:
Because , the line always passes through the point . The residual for a single point is the observed value minus the predicted value:
A positive residual means the model underpredicts that point, and a negative residual means it overpredicts.
How to use the calculator
- Paste or type your data as pairs, one pair per line or in two columns.
- Read the correlation coefficient and the coefficient of determination .
- Read the least-squares line in the form , with the slope and intercept filled in.
- Check the residual for any point, or plug an value into the line to get a predicted .
Keep predictions inside the range of values you entered. Predicting for an beyond that range is extrapolation, and the estimate gets less reliable the further out you go. Predicting for an inside the range is interpolation. The worked examples below reproduce every number by hand so you can check the tool or redo it on paper.
How to read r and r-squared
The sign of gives direction and the size gives strength. A value near is a strong positive linear association, a value near is a strong negative linear association, and means no linear association. Values of or mean a perfect linear association.
Use this template for : "There is a [strong or moderate or weak] [positive or negative] linear association between [ in context] and [ in context]."
Use this template for : "About [ as a percent] of the variation in [ in context] is explained by the linear relationship with [ in context]."
Two cautions. A value of close to or does not by itself mean a linear model is appropriate, so you still check a residual plot. And a strong correlation does not mean causes , because correlation does not imply causation.
How to read the slope, intercept, and residuals
Interpret the slope with a rate of change: "For each additional 1 unit of [ in context], the predicted [ in context] changes by units." Use "increases" when is positive and "decreases" when is negative.
Interpret the intercept as the predicted response when : "When [] is 0, the model predicts [] is ." This only carries real meaning when is inside or near your data.
Interpret a residual with its sign: "The model underpredicts (positive residual) or overpredicts (negative residual) the observed [] by that amount." A residual plot, which graphs residuals against the predicted values or against , helps you judge whether the linear model fits. Apparent random scatter supports a linear form, while a clear curve suggests a linear model is not the best choice.
Find r, r-squared, the line, and one residual for 5 points
You collect five paired observations: , , , , . Find the correlation coefficient , the coefficient of determination , the least-squares line , and the residual for the point at . Treat the data as a sample.
Find the means. and .
List the deviations from the means. For : . For : .
Multiply the paired deviations and add: .
Square the deviations and add each column: and .
Compute the correlation: .
Square it for the coefficient of determination: , so about 85.96% of the variation in is explained by the linear relationship with .
Compute the slope. .
Compute the intercept: . The line is .
Find the residual at , where the observed . Predicted: . Residual .
, , and the least-squares line is . The residual at is , so the model underpredicts that observation by 1.2.
Confirm the slope with b = r times s_y over s_x
Using the same five points, confirm the slope with the formula , given . Find the sample standard deviations first.
From the previous example, and , with .
Sample standard deviation of : .
Sample standard deviation of : .
Apply the formula: .
Recompute the intercept as a check: .
and , matching the first example, so .
Frequently asked questions
What counts as a good r value?
It depends on the context, not a fixed cutoff. The closer is to or , the stronger the linear association, and near means little or no linear association. A high still does not prove a line is the right model, so check a residual plot as well.
What is the difference between r and r-squared?
The correlation coefficient runs from to and shows both direction and strength of the linear association. The coefficient of determination runs from to and is the proportion of variation in explained by the linear relationship with . See r vs r-squared.
Does a strong correlation mean x causes y?
No. A strong correlation only says the two variables tend to move together in a linear pattern. A change in one variable causing a change in the other is a separate claim that a correlation alone cannot support.
Can I use a calculator like this on the AP exam?
On the AP Statistics exam a graphing calculator with statistical capabilities is expected for both sections, and it will report , , and the regression line for you. This tool is for practice and for checking work by hand.