Skip to content

Math

Linear Regression Calculator

Enter paired X and Y values as comma-separated lists of equal length. The calculator fits a least-squares line and reports the slope, intercept, equation, r², and sample size. The line minimizes the squared vertical distances from the data points. Use it to describe a straight-line trend, not to prove cause and effect.

Updated 2026-11-12 Editorial estimate Calccc Editorial Team Free · No sign-up

Loading calculator…

What this calculator does

Linear regression fits a straight line through paired data. This calculator uses the least-squares method, which chooses the line that keeps the total squared vertical error as small as possible. It returns the slope, intercept, equation, r², and sample size. The slope says how much Y changes, on average, when X rises by one unit. The intercept is the predicted Y when X is zero, which may or may not make sense in context.

How to use it

  1. Enter X values separated by commas.
  2. Enter Y values in the same order and with the same count.
  3. Match each X to its Y.
  4. Read the slope, intercept, equation, r², and sample size.

How it works

With n pairs, slope b = (nΣxy - ΣxΣy) / (nΣx² - (Σx)²). Intercept a = (Σy - bΣx) / n. The fitted equation is y = bx + a. R² = (nΣxy - ΣxΣy)² / [(nΣx² - (Σx)²)(nΣy² - (Σy)²)]. The denominator must be nonzero, so the X values need at least two different numbers. R² ranges from 0 to 1.

Example calculations

Example 1: moderate positive fit

For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5, the line is y = 0.6x + 2.2. The slope is 0.6, the intercept is 2.2, r² = 0.60, and n = 5. The points rise, but not exactly on the line.

Example 2: perfect negative fit

For x = 1, 2, 3, 4 and y = 10, 8, 6, 4, the line is y = -2x + 12. The slope is -2, the intercept is 12, r² = 1.00, and n = 4. Every point lies on the line.

Example 3: weak fit with three points

For x = 1, 2, 3 and y = 3, 1, 2, the line is y = -0.5x + 3. The slope is -0.5, the intercept is 3, r² = 0.25, and n = 3. The weak fit and tiny sample make the downward trend unreliable.

What the result means

The slope is the average change in Y per one-unit increase in X. The intercept is a prediction at X = 0 and is often outside the observed range, so do not assume it has a real-world meaning. R² ranges from 0 to 1 and describes the share of variation in Y explained by the linear fit; 0.60 means 60% under this model. A high R² does not prove the relationship is causal, and a low R² does not prove there is no relationship, because the pattern may be curved or noisy. Outliers can pull both the line and R². Always plot the pairs and check the sample size before trusting the equation.

Common mistakes

  • Reversing X and Y, which changes the slope and answers a different question.
  • Using lists of different lengths or pairing values out of order.
  • Treating r² as the percentage of the outcome caused by X.
  • Ignoring outliers or a curved pattern that a straight line cannot capture.

Assumptions and limits

  • Both lists contain numeric values and have the same number of entries.
  • Pairs are matched by position, so the order of each list matters.
  • A straight-line relationship is a reasonable description of the data.
  • Observations are independent of one another.
  • No missing values are imputed.

Frequently asked questions

What does the slope mean?

It is the estimated change in Y for a one-unit increase in X. A slope of 0.6 predicts a 0.6-unit rise in Y per unit of X.

What is the least-squares method?

It picks the line that minimizes the sum of squared vertical distances, giving large errors more weight.

What is a good r²?

There is no universal cutoff. A higher r² means the line explains more of the variation in Y, but usefulness depends on the field and purpose.

Can I use negative X values?

Yes. Negative X values are valid, and the intercept is more meaningful when zero is in the observed range.

What if my X and Y lists have different lengths?

The calculator needs one Y for every X. Check for a missing entry, an extra comma, or a stray character.

Does a strong regression prove causation?

No. A close fit shows that a straight line describes the sample well, but a third factor or reverse causation could explain the pattern.

Sources

This calculator is an educational statistics tool. Least-squares estimates depend on the values entered and on a linear model being reasonable. They do not establish causation or replace a full statistical analysis. Check the original data and consult a qualified analyst for research or business decisions.

2026 update

How to use the professional output

This page is not just a formula box. The result is designed to be checked, compared, and taken away.

  • Professional worksheet. The result includes the inputs used, the method and scope, and a one-variable sensitivity check for finance calculators.
  • A/B scenarios. Save two input sets in the browser and compare the primary, secondary, and breakdown figures side by side.
  • Print / PDF and CSV. Print a branded worksheet, or export the year-by-year table when the calculator produces one.

The formulas and assumptions above still govern the number. The worksheet makes the estimate auditable; it does not make it a lender quote, tax return, or personalized advice.

Go deeper

Guides that explain the math

Linear Regression: Slope, Intercept, and R-squared
Math

Linear Regression: Slope, Intercept, and R-squared

Fit a least-squares line by hand, read the slope and intercept in context, interpret R-squared honestly, and check the assumptions before trusting a prediction.

8 min read

Calccc Editorial Team · Updated 2026-11-12

Prepared by Calccc Editorial Team as an educational estimate. This page is not a licensed professional review and is not financial, medical, legal, or tax advice.

Editorial estimate prepared by the Calccc Editorial Team; not a licensed professional review.