Simple Linear Regression Calculator

Written by Thierno Sadou Diallo, formula verified per our methodology • Last checked on 9/5/2026

Simple linear regression finds the line y = slope × x + intercept that best fits a scatter of points, using the least squares method. For the perfectly linear relationship y=2x+1, the calculator finds exactly a slope of 2 and an intercept of 1.

Explanation

Simple linear regression looks for the line that best represents the overall trend of a scatter of points (x, y), by minimizing the sum of the squared vertical distances between each point and the line (the so-called least squares method). The result is expressed as an equation y = slope × x + intercept: the slope shows how much y changes on average for each one-unit increase in x, and the intercept gives the predicted value of y when x is zero. This calculator directly complements our Pearson correlation calculator, which answers a different, complementary question: correlation measures the strength and direction of a linear relationship between two variables (a number between -1 and 1), while regression gives its explicit equation, usable for estimating a y value from a new x value that wasn't measured directly. One important limitation to keep in mind: the regression line always fits the data to a linear model, even when the actual relationship between the two variables isn't linear — a mathematically valid fit can still be a poor summary of reality if the shape of the scatter plot clearly departs from a straight line, which is why it's always worth visualizing the data before interpreting a regression. The quality of this fit is in fact measured directly by the Pearson correlation coefficient: the closer it is to 1 or −1, the closer the points are to the line calculated here. As with our geometric and harmonic mean calculator, this statistical summary remains a condensed piece of information: it's always worth keeping the raw data behind any calculated coefficient in mind.

Example: the perfectly linear relationship y = 2x + 1

Inputs

Pairs (x, y): (1,3), (2,5), (3,7), (4,9).

Calculation

Since all the points are exactly aligned on the line y=2x+1, the least squares method finds exactly this same equation: slope = 2, intercept = 1.

Result

The regression line is y = 2x + 1, a perfect fit since all the points are exactly aligned.

Frequently asked questions

What does the calculated slope actually mean?

The slope shows the average change in y for each one-unit increase in x, following the overall trend of the scatter of points. A positive slope means y tends to increase as x increases, a negative slope means y tends to decrease, and a slope close to zero means there's no clear linear trend between the two variables.

Can this line be used to predict a y value outside the measured data?

Technically yes, by substituting a new x value into the equation, but this practice (extrapolation) becomes less and less reliable as the new x value moves further from the range of the actually measured data. Nothing guarantees the observed linear relationship still holds outside that range, a risk that grows the further the extrapolation goes.

What happens if all the points have the same x value?

In that case, the variance of x is zero, which makes the slope mathematically undefined (a vertical line has no slope in the usual sense): the site's engine then returns an undefined value for the slope and intercept, rather than a made-up result or a crash.

Related resources

Similar calculators