Skip to content
DeviceCheckHub

Linear Regression Calculator

Paste your x and y data to get the line of best fit, the correlation, a significance test and predictions, with a scatter plot, residuals and every step.

Your data

The least-squares line for your 11 points is ŷ = −173.513 + 4.82739x.

ŷ = −173.513 + 4.82739x

r = 0.6631, a positive linear relationship. p = 0.02615 is below 0.05, so the correlation is significant at the 5% level.

1001502002506567.57072.575

Dashed lines are 2s above and below the line; points outside them are marked as potential outliers.

Slope (b)
4.82739
Intercept (a)
−173.513
Correlation (r)
0.6631
r²
0.4397 (43.97% of the variation in y)
Standard error of the estimate (s)
16.4124
Slope test
t = 2.658, 9 df, p = 0.02615
95% CI for the slope
0.71824 to 8.93655
Points
11

At x = 73, the line predicts ŷ = −173.513 + 4.82739 × 73 = 178.886.

95% confidence interval for the average y at this x: 159.613 to 198.16.

95% prediction interval for one new y at this x: 137.054 to 220.718.

Residuals

−40−2002040
xyŷResidual
65175140.26734.7327
67133149.922−16.922
71185169.23215.7684
71163169.232−6.23163
66126145.095−19.0947
75198188.5419.4588
67153149.9223.07795
70163164.404−1.40423
71159169.232−10.2316
69151159.577−8.57684
69159159.577−0.576837

Step by step

  1. Means: x̄ = 69.1818 and ȳ = 160.455, from 11 points.
  2. Sums about the means: Sxx = Σ(x − x̄)² = 81.6364 and Sxy = Σ(x − x̄)(y − ȳ) = 394.091.
  3. Slope b = Sxy / Sxx = 394.091 / 81.6364 = 4.82739.
  4. Intercept a = ȳ − b x̄ = 160.455 − 4.82739 × 69.1818 = −173.513.
  5. Correlation r = Sxy / √(Sxx × Syy) = 394.091 / √(81.6364 × 4326.73) = 0.6631.
  6. Standard error of the estimate s = √(SSE / (n − 2)) = √(2424.3 / 9) = 16.4124.
  7. Standard error of the slope = s / √Sxx = 1.81648, so t = b / SE = 2.658 with n − 2 = 9 degrees of freedom. (The intercept’s standard error is 125.765.)
  • 1 point is more than 2s from the line: a potential outlier, marked in the chart and the table. Check it before deciding whether to keep it.

How to use the linear regression calculator

  1. Type or paste your x values and your y values in the same order, or switch to pairs and paste two columns straight from a spreadsheet. Up to 10,000 points work, separated by spaces, commas, tabs, semicolons or new lines.
  2. The line of best fit, r, r², the p-value and the charts update as you type.
  3. Optionally enter an x value to predict y, with a confidence interval and a prediction interval.

The calculator starts with a textbook data set: third-exam scores (x, out of 80) and final-exam scores (y, out of 200) for 11 statistics students, from OpenStax’s Introductory Statistics. Press Example data to bring it back at any time.

What linear regression does

Linear regression finds the straight line that best describes how y changes with x. “The process of fitting the best-fit line is called linear regression,” and the line it gives is written ŷ = a + bx, where ŷ (“y hat”) is the predicted value, b is the slope and a is the y-intercept.

“Best” has a precise meaning. For each point, the residual is the vertical gap between the actual y and the line’s ŷ. The least-squares line is the one that makes the sum of the squared residuals as small as possible: “Any other line you might choose would have a higher SSE than the best fit line.” Its slope and intercept come from simple formulas:

For the exam data this gives ŷ = −173.513 + 4.82739x. The calculator’s step-by-step section shows each of these sums for your own data.

Reading the slope and intercept

The slope tells you how much y changes, on average, for each one-unit increase in x. Here b = 4.82739: each extra point on the third exam goes with about 4.83 more points on the final, on average. The intercept is the predicted y when x is 0. It only has a real meaning when x = 0 is a sensible value inside your data; nobody scored 0 on the third exam, so here it is just where the line crosses the axis.

The correlation r and r²

The correlation coefficient r measures how closely the points follow a straight line. “The value of r is always between –1 and +1,” with values near −1 or 1 meaning a strong linear relationship and values near 0 meaning a weak one. Its sign matches the slope: positive when y tends to rise with x, negative when it tends to fall. A curved pattern can have an r near 0 even when x and y are closely related, so always look at the scatter plot too.

Squaring r gives the coefficient of determination, r², the share of the variation in y that the line explains. For the exam data r = 0.6631 and r² = 0.4397: about 44% of the variation in final-exam scores is explained by the third-exam scores, and the rest is the scatter of points around the line.

Is the relationship significant?

A sample can show some correlation just by chance. The calculator tests whether the true slope (equivalently, the population correlation) could be zero. The test statistic is t = b / SE(b), and “the p-value is calculated using a t-distribution with n - 2 degrees of freedom.” For the exam data, t = 2.658, 9 df, p = 0.02615, so at the 5% level the correlation is significant. A small p-value means a straight-line relationship is unlikely to be a fluke of this sample; it doesn’t say the relationship is strong or important.

The test assumes the relationship is linear and that the y values for each x are roughly normally distributed around the line with the same spread. The residuals plot is the quickest check: it should look like a random band around zero, with no curve or funnel shape.

Predictions and extrapolation

Plug an x into the equation to predict y. For a student who scored 73 on the third exam, the line predicts 178.886 on the final. The calculator gives two intervals around that number. The confidence interval covers the average final score of all students who scored 73; the prediction interval covers one individual student and is always wider.

Only predict inside the range of x values you have. “The process of predicting outside of the observed x values observed in the data is called extrapolation,” and the straight-line pattern may not hold out there. The calculator warns you when your x is outside the data.

Residuals and outliers

Each residual is y − ŷ: positive when the point is above the line, negative when it is below. OpenStax suggests a simple screen: “As a rough rule of thumb, we can flag any point that is located further than two standard deviations above or below the best-fit line as an outlier.” Here the standard deviation is s, the standard error of the estimate, 16.4124 for the exam data, so 2s is 32.8248. The student with (65, 175) is 34.7327 points above the line and is flagged.

A flagged point isn’t automatically wrong. It may be a typing mistake, or it may be real and important. Check it, and if you remove it, say so and report the results both ways.

Correlation isn’t causation

A strong, significant correlation shows that x and y move together, not that one causes the other. Both may be driven by a third factor, or the link may run the other way. As the textbook puts it, “correlation does not imply causation.” Establishing cause and effect needs a designed experiment or careful study, not just a fitted line.

Your data stays on your device

Everything is worked out in your browser. Nothing you type or paste is sent anywhere or stored.

Frequently asked questions

How do I paste data from Excel or Google Sheets?

Copy the x column and paste it into the x box, then do the same for y. Or choose “Pairs, one per line” and paste both columns at once; a first row of column names is skipped. Up to 10,000 points are accepted.

What is a good r value?

There is no single cut-off. r runs from −1 to 1, and values closer to −1 or 1 mean the points lie closer to a straight line. Whether a given r matters depends on the sample size, which is why the calculator also tests whether it is significant.

What is the difference between r and r²?

r gives the direction and strength of the straight-line relationship. r² is r squared: the share of the variation in y that the line explains. An r of 0.6631 gives an r² of 0.4397, so the line explains about 44% of the variation.

Why are there two intervals for a prediction?

The confidence interval is for the average y of everything with that x. The prediction interval is for one new observation, so it is wider: it also has to allow for how far single points scatter around the line.

Which variable should be x?

Put the variable you use to predict, the explanatory or independent variable, as x, and the one you want to predict as y. Swapping them gives a different line, so the calculator has a Swap x and y button if you need the other one.

Is my data uploaded?

No. Everything is worked out in your browser and nothing you type is sent anywhere or stored.

Last updated · About DeviceCheckHub