Linear Regression Calculator — Line of Best Fit & Correlation
StatisticsFreeNo sign-up
For hours studied (1 to 8) and test scores (55, 62, 63, 71, 74, 78, 86, 87), the least-squares line is ŷ = 51 + 4.667x: each extra hour predicts about 4.7 more points. The correlation is r = 0.991 and r² = 0.981. The linear regression calculator below gives this line for your data, plus standard errors, residuals and prediction intervals.
In words. Each 1-unit increase in x goes with a rise of about 4.66667 in predicted y. r = 0.990657 shows a very strong positive linear relationship, and the line explains 98.1% of the variation in y. The slope is statistically different from 0 at the 5% level (p < 0.0001).
Residuals table and plot (8 points)
| # | x | y | ŷ | Residual y − ŷ |
|---|---|---|---|---|
| 1 | 1 | 55 | 55.6667 | −0.666667 |
| 2 | 2 | 62 | 60.3333 | 1.66667 |
| 3 | 3 | 63 | 65 | −2 |
| 4 | 4 | 71 | 69.6667 | 1.33333 |
| 5 | 5 | 74 | 74.3333 | −0.333333 |
| 6 | 6 | 78 | 79 | −1 |
| 7 | 7 | 86 | 83.6667 | 2.33333 |
| 8 | 8 | 87 | 88.3333 | −1.33333 |
Show steps (sums table and formulas)
- Sums tableAdd up each column (n = 8):
x y x² y² xy 1 55 1 3,025 55 2 62 4 3,844 124 3 63 9 3,969 189 4 71 16 5,041 284 5 74 25 5,476 370 6 78 36 6,084 468 7 86 49 7,396 602 8 87 64 7,569 696 Σx = 36 Σy = 576 Σx² = 204 Σy² = 42,404 Σxy = 2,788 - Meansx̄ = Σx / n = 36 / 8 = 4.5; ȳ = Σy / n = 576 / 8 = 72
- Sums of squaresSxx = Σx² − (Σx)²/n = 42; Syy = Σy² − (Σy)²/n = 932; Sxy = Σxy − (Σx)(Σy)/n = 196
- Slopeb₁ = Sxy / Sxx = 196 / 42 = 4.66667
- Interceptb₀ = ȳ − b₁·x̄ = 72 − (4.66667)(4.5) = 51. The line is ŷ = 51 + 4.66667x.
- Correlationr = Sxy / √(Sxx·Syy) = 196 / √(42 × 932) = 0.990657, so r² = 0.981402.
- Residual spreadSSE = Σ(y − ŷ)² = 17.3333. With n − 2 = 6 degrees of freedom, s = √(SSE / (n − 2)) = 1.69967.
- Standard errorsSE(b₁) = s / √Sxx = 0.262265; SE(b₀) = s·√(1/n + x̄²/Sxx) = 1.32437.
- t test for the slopet = b₁ / SE(b₁) = 17.7937 with 6 df, two-sided p < 0.0001. The 95% critical value is t* = 2.44691, so the slope interval is b₁ ± t*·SE(b₁) = 4.02493 to 5.30841.
- Prediction at x = 5.5ŷ = 51 + 4.66667·5.5 = 76.6667. Mean response: ŷ ± t*·s·√(1/n + (x₀ − x̄)²/Sxx) = 75.0623 to 78.271. One new observation: ŷ ± t*·s·√(1 + 1/n + (x₀ − x̄)²/Sxx) = 72.209 to 81.1243.
Related: describe each variable · standard deviation · p-values
How to use the linear regression calculator
- Enter your data in one of three ways: two comma-separated lists, pairs pasted from a spreadsheet (one x, y pair per line), or a table you fill in row by row. Switching tabs carries the data over.
- Optionally enter an x value to predict at, and choose a 90%, 95% or 99% confidence level.
- Read the equation ŷ = b₀ + b₁x, then the slope and intercept with their standard errors, r, r², the slope’s t test and its confidence interval.
- Check the scatter plot with the fitted line and the confidence and prediction bands, then open the residuals table and residual plot.
- Open Show steps for the sums table (Σx, Σy, Σx², Σy², Σxy) and every formula with your numbers in it.
The least-squares line
Simple linear regression fits the straight line ŷ = b₀ + b₁x that makes the sum of squared residuals, Σ(y − ŷ)², as small as possible. The formulas use the means x̄ and ȳ and three sums of squares:
- Sxx = Σx² − (Σx)²/n, Syy = Σy² − (Σy)²/n, Sxy = Σxy − (Σx)(Σy)/n
- Slope: b₁ = Sxy / Sxx
- Intercept: b₀ = ȳ − b₁x̄ (so the line always passes through the point (x̄, ȳ))
- Correlation: r = Sxy / √(Sxx·Syy), and r² is the share of the variation in y explained by the line
The slope is the predicted change in y for a 1-unit increase in x. The intercept is the predicted y when x = 0, which only has a practical meaning if x = 0 is inside or near your data.
Worked example by hand
Take the five points (1, 2), (2, 4), (3, 5), (4, 4), (5, 5).
| x | y | x² | y² | xy |
|---|---|---|---|---|
| 1 | 2 | 1 | 4 | 2 |
| 2 | 4 | 4 | 16 | 8 |
| 3 | 5 | 9 | 25 | 15 |
| 4 | 4 | 16 | 16 | 16 |
| 5 | 5 | 25 | 25 | 25 |
| Σ = 15 | Σ = 20 | Σ = 55 | Σ = 86 | Σ = 66 |
The means are x̄ = 3 and ȳ = 4. Then Sxx = 55 − 15²/5 = 10, Syy = 86 − 20²/5 = 6 and Sxy = 66 − 15·20/5 = 6. The slope is b₁ = 6/10 = 0.6 and the intercept is b₀ = 4 − 0.6·3 = 2.2, so ŷ = 2.2 + 0.6x. The correlation is r = 6/√(10·6) ≈ 0.775 and r² = 0.6: the line explains 60% of the variation in y.
Standard errors, the t test and intervals
Real data scatter around the line, so the slope and intercept are estimates. The residual standard error s = √(SSE/(n − 2)) measures the typical vertical distance from the points to the line. In the example the residuals are −0.8, 0.6, 1, −0.6 and −0.2, so SSE = 2.4 and s = √(2.4/3) ≈ 0.894.
- Standard error of the slope: SE(b₁) = s/√Sxx ≈ 0.894/√10 ≈ 0.283.
- t test for the slope: t = b₁/SE(b₁) ≈ 2.12 with n − 2 = 3 degrees of freedom gives a two-sided p ≈ 0.124. With five points the upward trend is not statistically significant at the 5% level, even though r² = 0.6.
- Confidence interval for the slope: b₁ ± t*·SE(b₁), where t* is the Student t quantile for n − 2 degrees of freedom (3.182 for 95% and 3 df).
- Confidence interval for the mean response at x₀: ŷ ± t*·s·√(1/n + (x₀ − x̄)²/Sxx). It describes where the average y lies for that x.
- Prediction interval for one new y at x₀: ŷ ± t*·s·√(1 + 1/n + (x₀ − x̄)²/Sxx). It is always wider, because a single observation also carries its own scatter.
Both intervals are narrowest at x̄ and widen as x₀ moves away from it, which is why the bands on the scatter plot curve outward.
Reading r and r²
| |r| | Usual description | r² |
|---|---|---|
| 0.8 to 1 | very strong | 0.64 to 1 |
| 0.6 to 0.8 | strong | 0.36 to 0.64 |
| 0.4 to 0.6 | moderate | 0.16 to 0.36 |
| 0.2 to 0.4 | weak | 0.04 to 0.16 |
| 0 to 0.2 | very weak or none | 0 to 0.04 |
These labels are rules of thumb, not fixed standards; fields differ. The sign of r matches the sign of the slope. A high r² does not prove that x causes y, and a low r² does not rule out a strong curved relationship.
Check the residuals before you trust the line
Linear regression assumes a straight-line trend, independent observations and residuals with roughly constant spread (and roughly normal, for the t intervals). The residual plot is the quickest check: a patternless band around 0 is what you want. A curve means a straight line is the wrong shape; a funnel means the spread grows with x; one point far from the rest may be an outlier that pulls the line. The largest residual is highlighted in the table.
Common mistakes
| Mistake | Fix |
|---|---|
| Swapping x and y | Put the explanatory variable in x; regressing y on x and x on y give different lines |
| Predicting far outside the data | Extrapolation is risky; the calculator warns when x₀ is outside your range |
| Using the confidence interval for one new value | Use the prediction interval for a single observation |
| Reading r² = 0.81 as “r = 0.81” | r = ±0.9; r² is the share of variation explained |
| Rounding the slope before computing the intercept | Keep full precision and round only the final answers |
Linear Regression practice quiz: 10 questions
Test yourself with 10 multiple-choice questions. Choose an answer and press Submit to see if you are right and why. Your score appears at the end.
The points rise by 2 for each step in x and (1, 3) is on the line, so b₁ = 2 and b₀ = 3 − 2 = 1. All points lie exactly on it.
Square r: (−0.7)² = 0.49, so the line explains 49% of the variation in y. r² is never negative.
The prediction interval adds the scatter of a single observation, the extra 1 under the square root, so it is always wider.
Simple linear regression estimates two parameters (slope and intercept), so df = n − 2 = 10.
The slope is the predicted change in y per 1-unit increase in x; the negative sign means a decrease.
Sxx = 10, Syy = 6 and Sxy = 6, so r = 6/√60 ≈ 0.775. The value 0.6 is r², not r.
Residuals should look like a random band around 0. A curved pattern means the relationship is not linear.
Quiz complete
Frequently asked questions
What does linear regression calculate?
It finds the straight line that best fits paired data by least squares, ŷ = b₀ + b₁x, along with the correlation r and r². This calculator also gives the standard errors of the slope and intercept, a t test for the slope, residuals and confidence and prediction intervals.
What is a linear regression equation?
It is the fitted line written as ŷ = b₀ + b₁x. In ŷ = 52 + 4.5x for hours studied and test score, each extra hour predicts about 4.5 more points, and 0 hours predicts about 52.
How do you find linear regression on a TI-84?
Enter the x values in L1 and the y values in L2 (STAT, EDIT). Then press STAT, CALC, 4:LinReg(ax+b) and calculate. To see r and r², turn on DiagnosticOn from the CATALOG once (or turn Stat Diagnostics on in MODE on newer models).
How do you find linear regression without a calculator?
Make a table with columns x, y, x², y² and xy, add each column, then compute Sxx, Sxy, the slope b₁ = Sxy/Sxx and the intercept b₀ = ȳ − b₁x̄, as in the worked example above. The steps in the calculator show the same table for your data.
How do you find r in linear regression?
Use r = Sxy / √(Sxx·Syy). It always lies between −1 and 1. For example, r = 0.9 gives r² = 0.81, so the line explains about 81% of the variation in y.
Is there a linear regression calculator with steps?
Yes. The calculator on this page shows the full sums table and every formula with your numbers: means, sums of squares, slope, intercept, r, the residual standard error, standard errors, the t test and the intervals.
Related calculators
- Descriptive statistics calculator
- Standard deviation calculator
- Slope calculator
- P-value calculator
- Confidence interval calculator
- Equation of a line calculator
More statistics calculators
Related to This Article
More math articles
- How to Apply Trigonometry: Practical Uses and Insights into Engineering and Astronomy
- Alaska AK STAR Grade 4 Math Free Worksheets: Standards-Aligned Practice PDFs, No Signup Required
- Free Grade 8 English Worksheets for Indiana Students
- Top 10 6th Grade PARCC Math Practice Questions
- Free Grade 6 English Worksheets for Montana Students
- Division of Labor, Alienation, Labor Markets, and Professions
- Top 10 3rd Grade NYSE Math Practice Questions
- The Best Grade 7 ELA Practice Tests for Massachusetts Students
- Spinning the Numbers: The Hidden Math Inside Slot Games
- 7th Grade WVGSA Math Worksheets: FREE & Printable





What people say about "Linear Regression Calculator: Line of Best Fit, r, r²"?
No one replied yet.