Ad Space
Best-Fit Equation
Slope (b)
Intercept (a)
Predicted Y

Your Data + the Best-Fit Line

The line is the equation that best predicts Y from X across all your points. The closer your points hug the line, the more reliable predictions from that equation will be — scattered points mean the line is a weaker fit.

Ad Space

How to Calculate a Linear Regression Line

Simple linear regression finds the straight line that best fits a set of paired data points, using the least-squares method to minimize the sum of squared vertical distances between each point and the line. The line is defined by a slope and an intercept.

b=(xixˉ)(yiyˉ)(xixˉ)2a=yˉbxˉb = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \qquad a = \bar{y} - b\bar{x}

b: the slope of the regression line.

a: the y-intercept of the regression line.

xi, yi: each individual paired X and Y value in the dataset.

x̄, ȳ: the mean of all X values and the mean of all Y values.

Once you have the slope (b) and intercept (a), the fitted line is y=a+bxy = a + bx, which you can use to predict Y for any value of X within (or reasonably close to) your original data range.

Interpreting Slope and Intercept

The slope tells you the average change in Y for every 1-unit increase in X — a slope of 1.5 means Y rises by 1.5 units, on average, per unit of X. The intercept is the predicted Y when X is exactly zero; it's only practically meaningful if zero is a realistic value for your X variable, otherwise treat it as just the line's mathematical starting point.

What R² Tells You Here

R² (the same value as the squared Pearson correlation coefficient) tells you what proportion of the variation in Y is explained by its linear relationship with X. An R² of 0.85 means 85% of the variability in Y is accounted for by the fitted line, with the remaining 15% due to other factors, noise, or a relationship that isn't purely linear.

The Danger of Extrapolation

A regression line is only validated across the range of X values in your original data. Predicting Y for an X value far outside that range — extrapolation — assumes the same linear pattern continues indefinitely, which is often not true in the real world. Use predictions near or within your data's original range with far more confidence than predictions well beyond it.

A Brief History of Linear Regression

The least-squares method behind linear regression was developed independently by two mathematicians around the same period: Adrien-Marie Legendre published the technique first, in 1805, applying it to astronomical calculations, while Carl Friedrich Gauss claimed (with some historical dispute over priority) to have used the same method even earlier, around 1795, in his own astronomical work — he published his version in 1809. The term "regression" itself comes from an unrelated but historically linked source: Francis Galton's 1886 study of height, where he observed that children of unusually tall or short parents tended to be closer to the average height than their parents — a phenomenon he called "regression toward mediocrity" (now known as regression to the mean). The name stuck to the broader statistical technique even though modern regression analysis is used for far more than studying this specific "shrinking toward average" effect.

Common Linear Regression Mistakes

Extrapolating far beyond the original data's range, as covered above, is one of the most consequential errors, since a linear pattern validated only within a certain range offers no guarantee it continues to hold outside it. Fitting a straight line to data that's actually curved or has a more complex relationship is another common mistake — a low R² can be a signal that a linear model simply isn't the right fit, not necessarily that there's no relationship at all. Confusing correlation strength (R²) with the practical significance of the slope is a third: a very high R² can still come with a slope too small to matter in a real-world context, and vice versa.

Linear Regression Terms You Should Know

Least-Squares Method — the standard technique for fitting a regression line by minimizing the sum of the squared vertical distances between the line and each data point.

Slope — the predicted change in Y for each one-unit increase in X.

Intercept — the predicted value of Y when X equals zero, which may or may not be meaningful depending on the context of the data.

Residual — the difference between an actual observed Y value and the value the regression line predicts for that X.

Frequently Asked Questions

What is the least-squares method?

Least squares finds the line that minimizes the sum of the squared vertical distances between each data point and the line. Squaring the distances ensures points above and below the line don't cancel out, and it penalizes large errors more than small ones.

How do I interpret the slope of a regression line?

The slope tells you how much Y is predicted to change for every 1-unit increase in X. A slope of 2.5 means Y increases by 2.5 units on average for each 1-unit increase in X; a negative slope means Y decreases as X increases.

How do I interpret the intercept?

The intercept is the predicted value of Y when X equals zero. It's only meaningful if X = 0 is a realistic or interpretable value within your data's context — otherwise it's just a mathematical anchor point for the line.

Can I use this equation to predict values outside my data range?

Be cautious extrapolating beyond the range of X values you actually observed. The linear relationship you fit is only verified within that range — outside it, the true relationship could curve, level off, or behave completely differently.

Ad Space