Smekys
Ad Space

Regression Line Calculator

Free regression line calculator: fit an OLS line y = mx + b from paired data. Get slope, intercept, R² and slope confidence interval instantly.

Enter Values

points

How many (x,y) points you are entering (1 to 8).

units

First X value (e.g. hours studied for student 1).

units

Second X value.

units

Third X value.

units

Fourth X value.

units

Fifth X value.

units

Sixth X value (leave at 0 if fewer points).

units

Seventh X value (leave at 0 if fewer points).

units

Eighth X value (leave at 0 if fewer points).

units

First Y value, paired with X1.

units

Second Y value, paired with X2.

units

Third Y value, paired with X3.

units

Fourth Y value, paired with X4.

units

Fifth Y value, paired with X5.

units

Sixth Y value, paired with X6.

units

Seventh Y value, paired with X7.

units

Eighth Y value, paired with X8.

Result

Slope (b1)
0.6
Intercept (b0)
2.2
Regression Equation
1
Pearson Correlation (r)
0.77
Coefficient of Determination (r²)
0.6
Number of Points (n)
5
Mean of X
3
Mean of Y
4
Slope 95% CI — Lower
0.05
Slope 95% CI — Upper
1.15

A regression line is the single straight line that best fits a cloud of scattered data points. It is the workhorse of applied statistics: economists fit it to prices and demand, scientists fit it to dose and response, and marketers fit it to ad spend and revenue. This calculator fits an ordinary least squares (OLS) regression line to two paired lists of numbers — the same method used by Excel's SLOPE/INTERCEPT, Google Sheets' LINEST, and scipy's linregress.

Enter each pair in the numbered X and Y boxes (up to eight pairs at a time) and you instantly get the slope, the intercept, the regression equation, the Pearson correlation r, the coefficient of determination r², and a 95% confidence interval on the slope. Positive slope means Y rises as X rises; negative slope means Y falls as X rises; r² tells you what share of the variation in Y the straight line actually explains.

How to Use

  1. Set Number of Points to how many (x,y) pairs you have, then enter each X value — your independent variable. For example, the hours studied for each student.
  2. Enter each Y value — your dependent variable, paired with X in exactly the same row order. If the first X belongs to student one, the first Y must also belong to student one.
  3. Keep the two lists the same length. With eight rows of data, fill X1–X8 and Y1–Y8; if you have fewer points, set Number of Points to that count and leave the extra boxes at 0. A length mismatch is the most common error.
  4. Read the result card: Slope (b1) is the headline number — how much Y moves for each one-unit move in X. Intercept (b0) is where the line crosses the Y axis when X = 0. The Regression Equation line puts the two together in plain math.
  5. Use r² to judge quality. r² = 1.00 means every point lies exactly on the line; r² = 0.50 means the line explains half the scatter; r² near 0 means a straight line is not a useful model at all. The 95% confidence interval on the slope shows the range of plausible slope values given your sample size.

A few practical notes. Decimals and negative numbers are fine (temperature below zero, below-average sales). You need at least three paired points; with only two points the line is exact but statistically meaningless. OLS assumes the relationship is roughly linear — if your data curves, a straight-line fit will mislead you, which the examples below illustrate.

The OLS Regression Formula

The ordinary least-squares line picks slope b1 and intercept b0 that minimize the sum of squared vertical distances from the points to the line:

b1 = (n·Σxy − Σx·Σy) / (n·Σx² − (Σx)²)

b0 = ȳ − b1·x̄

Where n is the number of paired points, x̄ and ȳ are the means of X and Y, and Σ means "sum over all points." The numerator is the same cross-product used in the Pearson correlation; the denominator normalizes it by the spread in X. That is why slope and correlation always carry the same sign.

The Pearson correlation r reuses the same numerator:

r = (n·Σxy − Σx·Σy) / √( (n·Σx² − (Σx)²) · (n·Σy² − (Σy)²) )

and r² (the coefficient of determination) is simply r squared. If r = 0.90, then r² = 0.81, meaning about 81% of the variation in Y is linearly explained by X. The remaining 19% comes from other factors and noise.

The confidence interval on the slope uses the standard error of the slope, SE(b1) = s / √(Σ(xᵢ − x̄)²), where s = √(SSE/(n−2)) is the residual standard deviation. The interval reported here is b1 ± 1.96·SE(b1), which is the 95% normal-approximation interval used by most published studies. A wide interval warns you that the slope estimate is unstable until you collect more data.

Examples

Example 1 — A perfect straight line. X = 1, 2, 3, 4, 5 and Y = 2, 4, 6, 8, 10. Each Y is exactly double X, so the points lie on a line with slope 2.00 and intercept 0.00. The regression equation is y = 2x + 0, r = 1.000, r² = 1.000. This is the textbook ceiling; real-world data almost never reaches it.

Example 2 — Study hours vs test score. X = 1, 2, 3, 4, 5, 6, 7, 8 hours studied; Y = 65, 70, 72, 78, 80, 85, 88, 92 (percent scores). The calculator gives slope ≈ 3.81, intercept ≈ 61.61, so the fitted line is y = 3.81x + 61.61. r ≈ 0.997 and r² ≈ 0.994 — about 99% of the variation in score is explained by study hours. The 95% confidence interval on the slope is roughly 3.56 to 4.06, meaning each extra hour predicts between about 3.6 and 4.1 extra points.

Example 3 — Training hours vs error count (negative slope). X = 1, 2, 3, 4, 5, 6 hours of worker training; Y = 100, 90, 80, 60, 45, 30 defects per 1,000 units. Here slope ≈ −14.43 and intercept ≈ 118.0, giving y = −14.43x + 118.0. r ≈ −0.994, r² ≈ 0.988: each extra hour of training cuts defects by about 14.4 per thousand. The negative sign is meaningful — more training, fewer defects.

Example 4 — Ad spend vs revenue. X = $200, $350, $500, $650, $800, $950 monthly ad spend; Y = $420, $610, $780, $940, $1,150, $1,320 revenue. The fitted line slopes upward steeply and r² is near 1.00 — but remember that a high r² does not prove the ads caused the revenue. It only describes the past pattern.

Example 5 — The trap of r² ≈ 0. X = −3, −2, −1, 0, 1, 2, 3 and Y = 9, 4, 1, 0, 1, 4, 9 (Y is X squared). Because the points form a symmetric U-shape, OLS fits a flat horizontal line: slope ≈ 0, intercept ≈ 4, r² ≈ 0.00 — yet the relationship is perfectly deterministic. This is why a low r² does not always mean "no relationship"; it means no straight-line relationship. Always plot your data.

FAQ

What is a regression line in simple terms?

A regression line is the straight line that best summarizes the relationship between two variables on a scatter plot. It has two numbers: a slope (how much Y changes when X goes up by 1) and an intercept (where the line crosses the Y axis when X = 0). The line is written as y = slope·x + intercept, and it is the line that minimizes the squared vertical distances from all the data points.

How is the regression slope calculated?

The slope is b1 = (n·Σxy − Σx·Σy) / (n·Σx² − (Σx)²), where n is the number of paired points, Σxy is the sum of x·y products, Σx is the sum of X, and Σx² is the sum of X squared. This is the same formula used by Excel's SLOPE function, Google Sheets' LINEST, and scipy's linregress.

What is the difference between r and r²?

r (Pearson correlation) is a number from −1 to +1 that tells you both the direction and strength of the linear relationship. r² (the coefficient of determination) is r squared, expressed as a 0% to 100% figure: the share of variation in Y explained by the linear model. r = 0.80 gives r² = 0.64 (64% explained); r = 0.50 gives only r² = 0.25 — strength drops off faster than it looks.

What does a slope of 1.5 mean?

A slope of 1.5 means that, according to the fitted line, every one-unit increase in X is associated with a 1.5-unit increase in Y. If X is "hours studied" and Y is "test score in points," then each extra hour predicts a 1.5-point gain, on average. The intercept tells you the predicted score at zero hours studied.

Can I use a regression line to predict outside my data range?

You can compute a prediction, but be careful — that is called extrapolation. If your X data runs from 1 to 8 hours, predicting at X = 100 assumes the same straight-line relationship holds far beyond what you observed. Real relationships often curve or flatten out. Predictions inside your observed X range (interpolation) are far more reliable.

Why is my slope near zero even though the data looks related?

OLS only fits a straight line. If your data forms a U-shape, a curve, or any non-linear pattern, the best-fit straight line may have a slope close to zero and r² close to zero, even though X and Y are tightly linked. Always plot a scatter plot before concluding there is no relationship.

How many data points do I need?

You need at least three pairs for the formula to run, but small samples are unreliable. With n = 5, a single outlier can flip the slope sign. The confidence interval on the slope widens sharply when n is small — collect more observations before making decisions, and treat any interval that includes zero as "no evidence of a real linear trend."

Related Calculators

Disclaimer

This regression line calculator is provided for informational purposes only and does not constitute statistical, academic, financial, or medical advice. Results are computed with the ordinary least-squares formulas and a normal-approximation 95% confidence interval from the exact values you enter; they may differ slightly from other tools due to rounding, finite-sample t-versus-z critical values, missing-data handling, or outlier conventions. Always verify critical decisions with a qualified statistician and inspect a scatter plot before interpreting the result.

Related Calculators

Disclaimer

Results are estimates for illustration only. Verify important figures independently.