How to use the linear regression calculator
Paste the X numbers in the first box and the Y numbers in the second (a column from Excel works), or switch to one pair per line, or to the summary numbers if all you have are n, the means and the sums of squares. The line, its intervals, R² and a picture of your data appear as you type. Type X values under “Predict” to get Y with its interval, or a Y value to find the X.
Go advanced to fit a quadratic or cubic curve, force the line through zero, give each pair a weight, or name the variables. Use “Show squares” on the picture to see the squared errors the line makes as small as possible.
The linear regression formula
Worked out with this calculator for the 15 heights (m) and masses (kg) in the Wikipedia article on simple linear regression: slope 61.272, intercept −39.062, standard errors 1.776 and 2.938, 95% intervals 57.44 to 65.11 for the slope and −45.41 to −32.71 for the intercept, r = 0.9946, R² = 0.9892, F(1, 13) = 1190.36 and p = 3.604 × 10⁻¹⁴. A woman 1.60 m tall is predicted to weigh 58.97 kg (one-new-point interval 57.27 to 60.68 kg).
Straight line or curve?
For the same 15 pairs the quadratic fit raises R² from 0.9892 to 0.9989 and its extra term is significant (p = 2.566 × 10⁻⁷), while the cubic term is not (p = 0.06876): the points bend a little, as the Wikipedia article on ordinary least squares notes for this data set. The “Does a curve help?” table runs this comparison on your data every time.
Which points are steering the line?
A single extreme pair can tilt a line. The calculator computes Cook’s distance and the fit without each point. In the study example, pair #10 (X = 10, Y = 60) has a Cook’s distance of 1.80, above the cut-off 0.76, and leaving it out moves the slope from 2.497 to 3.950 and R² from 0.4854 to 0.9206.
Reading the result
The slope is the average change in Y per 1 of X; its p-value tests whether it differs from 0 and, for a straight line, equals the p-value of the whole fit. R² is the share of the variation in Y the line explains; adjusted R² corrects it for the number of terms. S is the typical size of an error in Y units, so a prediction is usually within about 2 S of the line. The two intervals for a prediction differ: the narrow one is for the average Y at that X, the wide one for one new observation.
Through the origin and weights
Forcing the line through (0, 0) changes the study example’s slope from 2.497 to 9.992. R² is then measured against zero, not the mean, so it is higher and not comparable. Weights make pairs with a larger weight count more, as when each point stands for a different number of people.
Quadratic fit on the study data
Fitting a quadratic curve to the study numbers gives Y = 40.97 + 8.25 X − 0.523 X², with R² = 0.6216 against 0.4854 for the line.
How many pairs do I need?
For the 15-pair example the smallest slope that would be significant at 0.05 is ±3.837; yours is 61.272. Keeping r at 0.6967, the study example reaches p below 0.05 with 9 pairs and about 14 pairs give 80% power (approximate, Fisher z).
Related tools
To measure how closely two variables move together use the correlation coefficient calculator; to compare two groups the t-test calculator; to turn a statistic into a p-value the p-value calculator; and to find a spread the standard deviation calculator.
Sources
- Slope = Sxy ÷ Sxx, intercept = ȳ − slope × x̄, the standard error of the slope and the interval estimate ± t* × standard error with n − 2 degrees of freedom follow the Wikipedia article “Simple linear regression”, read on 2026-11-24. Its worked example (15 heights and masses of American women aged 30–39) gives slope 61.272, intercept −39.062 and intervals −45.4 to −32.7 and 57.4 to 65.1; this calculator gives 61.272, −39.062, −45.41 to −32.71 and 57.44 to 65.11.
- The interval for the line and the prediction interval for one new point (s² × (1 ÷ n + (x − x̄)² ÷ Sxx), and the same with 1 added for one new point) follow the Wikipedia article “Prediction interval” (read 2026-11-23); for curves the same form is used with (XᵀX)⁻¹.
- Cook’s distance D = e² ÷ (p × s²) × h ÷ (1 − h)², and the cut-off at the median of F(p, n − p) (close to 1, with the note that opinions differ), follow the Wikipedia article “Cook’s distance” (read 2026-11-24). A leverage above 2p ÷ n marks a high-leverage point, following “Leverage (statistics)” (read 2026-11-24). A standardized error beyond ±2 is a common rule of thumb and is labelled so.
- Check: the 13-pair example that Stats Kingdom loads with its Example button (read on 2026-11-24) gives the same equation Ŷ = 1.4021 + 0.6021 X, slope interval 0.4646 to 0.7395, F(1, 11) = 92.96 and p = 0.000001063 as this page, and the same numbers for a prediction at X = 7 (5.6166, interval of the line 4.0066 to 7.2265, prediction interval −0.3349 to 11.5681).
- The feature set was compared with the regression tools of Omnicalculator, Pearson.com, Social Science Statistics, Statistics by Jim, Stats Kingdom, MiniWebtool and GraphPad, all opened on 2026-11-24. Probabilities come from the t and F distributions of this site’s p-value calculator. Pairs needed for 80% power use the Fisher z approximation on the correlation and are labelled approximate. Weights are used as relative weights in weighted least squares (scaled to an average of 1); through the origin, R² is measured against zero, not against the mean.
For information only. Check the assumptions of the method and your own data before drawing conclusions.
Common questions
What is linear regression?
Linear regression finds the straight line that best describes how Y changes with X. “Best” means the line with the smallest total of squared errors, the vertical distances from each point to the line. The result is an equation Y = a + b X: a is the intercept and b the slope.
How do I calculate a linear regression?
Paste the X numbers and the Y numbers, or one pair per line. The calculator finds the slope b = Sxy ÷ Sxx and the intercept a = ȳ − b × x̄. For the example on this page it gives Ŷ = 52.4667 + 2.4970 X.
What does the slope mean?
The slope is how much Y changes, on average, for each extra 1 of X. In the example each extra 1 of X goes with 2.50 more Y, give or take 0.91 (95% interval 0.40 to 4.59).
What does R² mean?
R² is the share of the variation in Y that the line accounts for. The example has R² = 0.4854, about 48.5%. It describes the fit of the line, not cause and effect, and it can only rise when you add curve terms: use adjusted R² (0.4211 here) to compare models.
How do I predict a value from the line?
Type one or more X values under “Predict Y”. You get the predicted Y with the interval for the line (the average Y at that X) and the wider interval for one new point. In the example, X = 11 gives 79.93 (new-point interval 56.88 to 102.99). Values outside your X range are flagged because the line may not hold there.
Can I find X from a Y value?
Yes. Type a Y value under “Predict X” and the calculator turns the straight line around: X = (Y − intercept) ÷ slope. That is not the same as fitting X on Y, which gives a different line unless the points sit exactly on a line.
Straight line, quadratic or cubic?
The “Does a curve help?” table compares the three on your data with R², adjusted R² and an F test of each extra term. For the 15 heights and masses used by Wikipedia the straight line gives R² = 0.9892, and the quadratic term is significant (p = 2.566 × 10⁻⁷): the points bend a little. Choose Curve under Go advanced to fit it.
Which points steer my line?
The “Which points are steering the line?” table shows, for the points with the largest Cook’s distance, the slope and R² you would get without each one. In the example, leaving out pair #10 (X = 10, Y = 60) moves the slope from 2.497 to 3.950.
What is “through the origin”?
It forces the line through (0, 0), so the intercept is 0. It suits cases where Y must be 0 when X is 0, such as a calibration with no blank. R² is then measured against zero rather than the mean, so it is not comparable with the normal R². In the example the through-zero slope is 9.992 against 2.497.
How many pairs do I need?
The “What would it take?” table gives the smallest slope that would be significant with your pairs, and how many pairs would be needed for p below 0.05 or 80% power if the correlation stayed the same. In the example, about 9 pairs already give p below 0.05 if r stays at 0.6967.
Can I use summary numbers instead of the data?
Yes. Choose “Summary numbers” and type n, the two means, Sxx, Syy and Sxy. You get the line, standard errors, intervals, R², F test and predictions, but no picture because there are no points.