Linear regression calculator

This linear regression calculator fits a straight line to your data by least squares. Paste X and Y values and get the regression equation, the slope and intercept with their standard errors, R², the p value for the slope, a prediction at any X with its confidence interval, and a scatter plot with the fitted line.

The numbers are calculated in your browser. Nothing you enter is sent or stored.

Linear regression calculatorOr describe it in Studio →

The first X goes with the first Y. The numbers stay in your browser.

Regression line

y = 2.2 + 0.6x

Slope
0.6 (SE 0.2828, 95% CI -0.3 to 1.5)
Intercept
2.2 (SE 0.9381)
R²
0.6
p (slope ≠ 0)
0.1240
Residual SD
0.8944
Predicted Y at X = 6
5.8 (95% CI of the mean 2.815 to 8.785)

X = 6 is outside your data (1 to 5). The line may not hold there.

To report

y = 2.2 + 0.6x, R² = .60, t(3) = 2.12, p = .124

Predicted values and residuals
XYPredictedResidual
122.8-0.8
243.40.6
3541
444.6-0.6
555.2-0.2
15
Check your result: the line always passes through the point (mean of X, mean of Y): 2.2 + 0.6 × 3 = 4. The residuals add up to zero, and t is the slope divided by its standard error: 0.6 ÷ 0.283 = 2.12.
line in the worked example
y = 2.2 + 0.6x
line in the worked example
R² in the example
0.60
R² in the example
95% CI of its slope
−0.30 to 1.50
95% CI of its slope
points at the least
3
points at the least
  • Equation of the best-fit line
  • Standard errors and 95% CI of the slope
  • R² and p value
  • Predictions and residuals table
  • Runs in your browser, free

01

How to use the regression calculator

  1. Paste the predictor values in the X box and the outcome values in the Y box, in the same order.
  2. Read the equation and R². They update as you type.
  3. Enter an X value to get the predicted Y.
  4. Check the plot, and open “Predicted values and residuals”: the residuals (observed minus predicted) should scatter around zero with no pattern.
residualxy
A fitted line and a residual. Each dot is one pair of measurements. The line is the one that makes the squared vertical distances as small as possible. A residual, the dashed segment, is the distance from a point to the line; the tighter the points hug the line, the closer r is to 1 or −1.

02

Linear regression formulas

slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
intercept a = ȳ − b × x̄
line: y = a + b × x

The slope is the change in Y for a one-unit increase in X. The intercept is the predicted Y when X is zero, which may or may not be a meaningful point for your data.

residual SD s = √( Σ(y − ŷ)² ÷ (n − 2) )
SE(b) = s ÷ √Σ(x − x̄)², t = b ÷ SE(b) on n − 2 degrees of freedom

03

Worked example

The calculator opens with X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5 (means 3 and 4).

b = 6 ÷ 10 = 0.6, a = 4 − 0.6 × 3 = 2.2, so y = 2.2 + 0.6x

QuantityValue
R²0.60
Residual SD0.894
SE of the slope0.283
95% CI of the slope−0.30 to 1.50
t (3 df), p2.12, p = .124
Predicted Y at X = 65.8 (95% CI of the mean 2.81 to 8.79)

The slope’s interval includes zero: five points are not enough to show a trend, even with R² = 0.60.

04

What R² means

R² is the share of the variation in Y that the line accounts for, from 0 to 1. With one predictor it equals the square of Pearson’s correlation (see the correlation coefficient calculator). A high R² does not show that the relationship is linear or causal, and a low R² can still go with a slope that is clearly not zero in a large sample.

05

Predictions and their limits

  • The interval shown is for the mean Y at that X. A single new observation varies more: its prediction interval is wider.
  • Predicting outside the range of your X values (extrapolation) assumes the line continues unchanged. The calculator warns when you do it.
  • The intervals are narrowest at the mean of X and widen toward the ends.

06

Assumptions to check on the plot

  • Linearity: the points follow a straight band, not a curve.
  • Constant spread: the scatter around the line is similar along its length, not a funnel.
  • Independence: each point is a separate observation, not repeated measurements of a few subjects.
  • No dominant outlier: one extreme point can set the slope almost by itself.

07

Common mistakes in simple regression

  • Swapping X and Y. Regressing X on Y in the worked example gives a slope of 1.0; turned round, that is not the 0.6 you get from Y on X. Put the variable you want to predict on the Y axis.
  • Letting one point set the line. Adding a single point at (10, 20) to the example moves the slope from 0.6 to 1.95 and R² from 0.60 to 0.88.
  • Quoting the interval for the mean as the range for one new value. At X = 6 the mean’s 95% CI is 2.81 to 8.79, but a single new observation should fall between 1.68 and 9.92.
  • Extrapolating. At X = 20, far outside 1 to 5, the line predicts 14.2 with a 95% CI of −1.16 to 29.6.

Trust

How this page is checked

  • The calculation runs on code with automated tests against worked reference values. Every number in the examples on this page was produced by that same code, not typed by hand.
  • The formulas and conventions used are stated on the page, so you can reproduce the result yourself or compare it with your own software.
  • Last reviewed by the Sciloom team, Zebra Nine Studio Inc. It is a tool for research and teaching, not a substitute for a statistician, a validated lab method or medical advice.

Cite this page

Sciloom. (2026). Linear regression calculator. Zebra Nine Studio Inc. https://sciloom.si/linear-regression-calculator

Read the full methodology · Who makes Sciloom

Frequently asked questions

How do I find the equation of the regression line?

Paste your X and Y values. The calculator computes the least-squares slope and intercept and writes the equation as y = a + bx.

What is the difference between regression and correlation?

Correlation measures how strongly two variables move together, as one number. Regression describes the line itself, so you can predict Y from X. With one predictor they give the same p value.

What does the p value of the slope mean?

It tests whether the true slope is zero. A small p value means the data show a linear trend that chance alone would rarely produce.

How many data points do I need?

At least three to fit a line and estimate its error, but estimates from fewer than about ten points are very imprecise, as the wide confidence interval will show.

Putting the fit in a paper? The figure legend generator states the equation, R² and n under the plot.
Free to start, no sign-up.
Back to the tool ↑

More research tools