Linear Regression Calculator

By Seagit ✨
Deploy to your own cloud with Seagit, today.Start freeNo credit card required

Fit a least-squares line to paired data and see every step

Paired data (x and y)

ŷ = 2.2000 + 0.6000 × x

n (pairs)5
Mean of x, x̄ = Σx / n3.0000
Mean of y, ȳ = Σy / n4.0000
Sxx = Σ(x − x̄)²10.0000
Syy = Σ(y − ȳ)²6.0000
Sxy = Σ(x − x̄)(y − ȳ)6.0000
Slope, b₁ = Sxy / Sxx0.600000
Intercept, b₀ = ȳ − b₁x̄2.200000
Pearson r = Sxy / √(Sxx·Syy)0.774597
r², share of variance explained0.600000
Residual SS = Syy − b₁Sxy2.400000
s = √(SSE / (n − 2))0.894427
SE(b₁) = s / √Sxx0.282843
t = b₁ / SE(b₁), df = n − 22.1213, df 3
Two-tailed p for slope = 00.124027

Predict y from x

ŷ = 2.2000 + 0.6000 × 6 = 5.8000. Predictions far outside the range of your x values are extrapolation, and the line may not hold there.

How the line is fitted

Least squares chooses the slope and intercept that make the sum of squared vertical distances from the points to the line as small as possible. The slope is b₁ = Sxy / Sxx, and the line always passes through (x̄, ȳ), which is why the intercept is b₀ = ȳ − b₁x̄. The t test on the slope asks whether the true slope could be zero; it uses n − 2 degrees of freedom because two parameters were estimated from the data.

📈 Linear Regression Calculator — Free Online Tool

Fit a least-squares line and see every step. Linear regression fits the straight line y = b0 + b1·x that comes closest to a set of paired points, by minimizing the sum of squared vertical distances. This calculator computes the slope, intercept, Pearson r, r², the residual standard error and a t test for the slope, and it shows the sums that produce each number so you can check the work by hand.

How to use it

  1. Paste the x values in one box and the y values in the other, in the same order. Commas, spaces and new lines all work.
  2. Check that both lists have the same count and at least three pairs.
  3. Read the slope and intercept, then the sums Sxx, Syy and Sxy they come from.
  4. Use the predict box to get ŷ for any x, and treat values far outside your data with caution.

🚀 Why use this Linear Regression Calculator tool?

Read r² and the slope test together. A large r² from a small sample can still be a weak result, and a significant slope does not show that x causes y. The line describes the linear association in the data you entered and nothing more. 100% free, no registration, and complete privacy — everything runs locally in your browser, so your data never touches a server.

Key Features

📐Slope and intercept from sums

b1 = Sxy / Sxx and b0 = ȳ − b1·x̄. The fitted line always passes through the point of means (x̄, ȳ).

🔗r and r² together

r = Sxy / √(Sxx·Syy) gives direction and strength. r² is the share of the variation in y that the line explains.

🧪Slope t test

SE(b1) = s / √Sxx and t = b1 / SE(b1), with n − 2 degrees of freedom, give a two-tailed p-value for H0: slope = 0.

🔮Prediction

Enter an x value to get the fitted ŷ, with the equation written out using the calculated coefficients.

Popular Use Cases

Trend lines in data

  • • Sales against advertising spend
  • • Temperature against time
  • • Response against dose in a lab test

Coursework and checking

  • • Verify a textbook slope by hand
  • • Compare with a spreadsheet's LINEST output
  • • Learn what the residual standard error means

Calibration

  • • Fit a standard curve from known samples
  • • Read an unknown from the line
  • • Report the slope with its standard error

What It Handles

Fit

  • ✓ Least-squares slope and intercept
  • ✓ Means, Sxx, Syy and Sxy shown
  • ✓ Predicted ŷ for any x

Strength

  • ✓ Pearson r and r²
  • ✓ Residual sum of squares
  • ✓ Residual standard error s

Inference

  • ✓ Standard error of the slope
  • ✓ t statistic with n − 2 df
  • ✓ Two-tailed p-value for slope = 0

Related Tools

Sources & References

Frequently Asked Questions

What does the slope tell me?

The slope is the average change in y for a one-unit increase in x, along the fitted line. If x is in hours and y in kilograms, a slope of 0.6 means about 0.6 kg more per extra hour, on average, within the range of your data.

What is the difference between r and r²?

r is the Pearson correlation, between −1 and +1, and it carries the sign of the slope. r² is its square, between 0 and 1, and gives the share of the variation in y that the line accounts for. With r = 0.77, r² is about 0.60, so about 60% of the variation in y is linearly associated with x.

Why does the slope test use n − 2 degrees of freedom?

The fitted line estimates two parameters, the slope and the intercept, so two degrees of freedom are used up. The residual variance is divided by n − 2 for that reason, and the t statistic follows a t distribution with n − 2 degrees of freedom when the errors are independent and roughly normal.

Can I use this with only two points?

A line through two points fits perfectly and says nothing about the scatter, so the calculator asks for at least three pairs. With three or more pairs, the residual error and the slope test become meaningful.

🎓 Pro Tips

  • Tip 1: Plot the points before trusting the line. A curve, outliers or clusters can give a sensible-looking slope that describes none of the data well.
  • Tip 2: Keep the units with the slope. The slope has the units of y divided by the units of x.
  • Tip 3: Avoid extrapolating far beyond the range of x in your data, where the linear pattern may stop.
  • Tip 4: Report the slope with its standard error or confidence interval, not the slope alone.
banner