Paste paired x and y values and get the least-squares regression line instantly — with the slope, intercept, R squared, residuals, prediction and confidence intervals, and a full ANOVA table.
A linear regression calculator fits the straight line that best describes paired data. Enter x and y values to get the slope and intercept, R squared, residuals, and a prediction with a 95% confidence interval and a 95% prediction interval.
Your paired data
Enter one pair per line, as x, y. Separate the two numbers with a comma, space or tab. At least 3 pairs are needed.
10 pairs found
How to read the slope
The slope is the change in y for a one-unit increase in x. A slope of 0.96 means y rises by about 0.96 when x rises by 1. The intercept is the predicted y when x is 0 — and it is only meaningful if 0 lies inside, or close to, the range of your x values.
Least-squares regression line
ŷ = 1.200 + 0.964x
Near-perfect positive relationship
R² = 0.929 · n = 10 · ŷ at x = 6 is 6.98
Results
Prediction at x = 6
Scatterplot with regression line
Residual table and residual plot
Residuals should scatter randomly around zero with no pattern. A curve, a funnel shape or a trend in the residuals means a straight line is not the right model for the data.
ANOVA table
Calculation ledger
How to use the linear regression calculator
Paste your paired data, choose the x value to predict at, and read the fitted line, R squared, residuals, intervals and ANOVA table.
- Paste the paired data. Paste one x, y pair per line in the data box. Separate each pair's two numbers with a comma, space or tab. At least 3 pairs are needed.
- Enter the x value to predict at. Type the x value you want a prediction for — for example, enter 6 to predict y when x is 6.
- Calculate the regression. Click Calculate regression. The calculator also updates as you type, so you can see the line change with the data.
- Read the answer. Read the slope, intercept, R squared and residuals, then the fitted line, the scatterplot, the residual plot, the prediction and confidence intervals, and the ANOVA table.
- Copy the link. Use the Copy link button to share the page or return to it later.
What is linear regression?
Linear regression fits a straight line to paired data. It finds the line that makes the total squared distance between the observed points and the line as small as possible — the least-squares line. The line is written as ŷ = a + bx, where ŷ is the predicted value of y, b is the slope and a is the intercept.
Use it when you have two continuous variables and you expect one to change roughly steadily as the other changes: study hours and exam score, advertising spend and sales, temperature and ice-cream sales. The related correlation coefficient calculator measures how strong the linear relationship is, while regression goes one step further and gives you the equation to predict with.
The slope b tells you how much y changes when x increases by one. The intercept a is the predicted y when x is 0. The line always passes through the point (x̄, ȳ) — the means of the two variables.
How to calculate linear regression by hand
Work through these five steps with your paired data:
- Find the means: x̄ = Σx / n and ȳ = Σy / n.
- Find the sums of squares and products: Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ).
- Divide for the slope: b = Sxy / Sxx.
- Work out the intercept: a = ȳ − b·x̄.
- Write the fitted line: ŷ = a + bx.
Worked example — the data in the calculator's example:
x̄ = 5.5 and ȳ = 6.5. The sums are Sxy = 79.5, Sxx = 82.5 and Syy = 82.5. So b = 79.5 ÷ 82.5 = 0.964 and a = 6.5 − 0.964 × 5.5 = 1.2. The fitted line is ŷ = 1.2 + 0.964x. The correlation is r = 0.964, R² = 0.929 and the residual standard error is s = 0.858. The sums Sxx and Syy are n − 1 times the squared standard deviations of x and y — see the standard deviation calculator for how those are found.
What does the slope tell you?
The slope tells you how much y is expected to change for a one-unit increase in x. A slope of 0.964 means y rises by about 0.964, on average, every time x rises by 1. A slope of −0.3 means y falls by about 0.3 for each one-unit increase in x. A slope of 0 means the line is flat: changes in x are not associated with any change in y.
The slope is in the units of y per unit of x. If x is study hours and y is an exam score out of 100, a slope of 4.5 means each extra hour of study is associated with about 4.5 extra marks. Always read the slope together with R² and the residual plot: a steep slope means little if the points scatter widely around the line.
The intercept a is the predicted y when x is 0. It is only meaningful when x = 0 is inside, or close to, the range of your data. For a line fitted to adult heights and weights, the intercept predicts the weight of a person 0 cm tall — a number with no real meaning.
How to interpret R squared
R squared is the share of the variation in y that the straight line explains. It runs from 0 to 1 (or 0% to 100%). R² = 0.929 means about 92.9% of the variation in y is explained by the linear relationship with x, and the remaining 7.1% is left in the residuals. R² = 0.09 means the line explains only 9% of the variation — the data barely follow a line at all.
| Pearson r | R² | Share of variance explained | Reading |
|---|---|---|---|
| 0.964 | 0.929 | 92.9% | Points hug the line |
| 0.50 | 0.25 | 25.0% | Moderate — most variation unexplained |
| 0.30 | 0.09 | 9.0% | Weak — the line explains little |
| 0.10 | 0.01 | 1.0% | Practically no linear relationship |
Note that R² is just r squared: the correlation coefficient squared. Adjusted R² corrects R² for the number of data points, so it can be a little lower — and it can even be negative when the fit is very weak. A high R² is not proof that x causes y: a strong association can come from a third factor. See correlation vs causation for the difference.
Residuals: the check for linearity
A residual is the gap between an observed value and the value the line predicts: e = y − ŷ. If a point lies above the line, its residual is positive; below the line, negative. The residuals always add up to (almost) zero — the least-squares line is balanced between the points.
Plotting the residuals against the fitted values is the standard check that a straight line is the right model. Look for one of these patterns:
| What the residual plot shows | What it means |
|---|---|
| Random scatter around zero, no shape | A straight line fits well |
| A clear curve or U-shape | The relationship is not linear — consider a curve or a transformed variable |
| A funnel that widens or narrows | The spread of y changes with x — the intervals may mislead |
| One point far from the rest | A possible outlier — check the value and its effect on the slope |
If the residuals look roughly normal and evenly spread, the t-tests and intervals from the regression are trustworthy. The normal distribution calculator shows the shape a normal set of residuals should have.
Prediction interval vs confidence interval — which one do I use?
Use the confidence interval when you want the average y at a given x, and the prediction interval when you want one single new value of y at that x. The prediction interval is always wider, because it has to allow for the scatter of one new point around the line, not just the uncertainty in the line itself.
| Confidence interval (mean response) | Prediction interval (new observation) | |
|---|---|---|
| Answers | Where is the average y at this x? | Where will one new y fall at this x? |
| Width | Narrower | Wider |
| Example at x = 6 | 6.35 to 7.62 | 4.90 to 9.06 |
| Use it for | Estimating a population mean | Forecasting one person's result |
Both are centred on the same prediction ŷ, and both use the same 95% level by default. The half-width of an interval is its margin of error — the confidence interval calculator shows the same idea for a single mean.
The ANOVA table: is the regression significant?
The ANOVA table splits the total variation in y, SST, into the part the line explains, SSR, and the part left over, SSE. SSR + SSE = SST. The F statistic compares the two: F = MSR ÷ MSE, where MSR = SSR ÷ 1 and MSE = SSE ÷ (n − 2).
For the example data, SSR = 76.61, SSE = 5.89 and SST = 82.50, so F = 104.04 with 1 and 8 degrees of freedom and p < 0.001 — the line explains far more variation than chance alone would. In simple linear regression F is the square of the slope's t-statistic (10.202 = 104.04), so the F test and the slope t-test always agree. The intervals use a t critical value with n − 2 degrees of freedom; the t-distribution calculator shows how those values are found.
Extrapolation: why predictions outside your data are unreliable
A regression line is only supported by the data it was fitted to. Predicting at an x value beyond the range of your data — extrapolation — assumes the straight line keeps going, but real relationships often bend, flatten out or change entirely outside the observed range. The tool warns you whenever your chosen x lies outside the data range.
As a rule, the further you move from the data, the wider the intervals grow and the less the prediction can be trusted. Inside the data range, the same intervals are the honest measure of uncertainty — and if the residuals are roughly normal, about 95% of them fall within two standard deviations of zero. The empirical rule probability finder shows the exact shares for one, two and three standard deviations.
Frequently asked questions
What is linear regression used for?
Linear regression is used to predict one variable from another and to measure how the two are related. It is used for forecasting sales from advertising spend, predicting exam scores from study hours, estimating house prices from floor area, and anywhere a straight-line relationship is a useful first model.
What does a negative slope mean?
A negative slope means y falls as x rises. With a slope of −0.3, y drops by about 0.3 for each one-unit increase in x. The size of the drop is the absolute value of the slope; the minus sign only gives the direction.
How do I interpret R squared?
Read R squared as the share of the variation in y that the line explains, as a number between 0 and 1. R² = 0.929 means 92.9% of the variation in y is explained by x. R² = 0.09 means only 9% is explained, so the line is a poor description of the data. Adjusted R² is the same idea, corrected for the number of data points.
What is the difference between a prediction interval and a confidence interval?
A confidence interval brackets the mean response — the average y at a given x. A prediction interval brackets one new individual observation at that x. The prediction interval is wider because a single new point can fall further from the line than the average does.
How many data points do I need for linear regression?
You need at least 3 pairs of values, because the line has two parameters and one degree of freedom must remain for the residuals (df = n − 2). In practice, use at least 10 points: with few points the slope and the intervals are unstable, and a single outlier can dominate the fit.
Can the slope be zero?
Yes. A slope of zero means the fitted line is flat at the mean of y: changes in x are not associated with any change in y. The t-test for the slope checks exactly this — a large p-value means the data do not show a slope different from zero.
What is the difference between linear regression and correlation?
Correlation measures the strength and direction of a linear relationship on a scale from −1 to 1; regression uses that relationship to predict y from x with an equation, ŷ = a + bx. The two are connected: R squared is the correlation squared, and the regression slope is the correlation scaled by the ratio of the standard deviations.
Why is extrapolation unreliable?
Extrapolation assumes the straight line continues beyond the data, but real relationships often bend or change outside the observed range. The further the chosen x is from the data, the wider the intervals become and the less the prediction can be trusted. Use the fitted line only within, or just beyond, the range of x values you actually observed.
Reference
The formulas on this page follow the NIST/SEMATECH e-Handbook of Statistical Methods (Engineering Statistics), which derives the least-squares estimates and their standard errors. See the regression chapter at the NIST/SEMATECH e-Handbook of Statistical Methods. Link verified live on 13 November 2026.
More Tools to Explore
Keep exploring the statistics toolbox — or browse all tools to see the full set.