Linear regression calculator
Paste your data pairs to get the line of best fit, r, R², and a plot.
Least squares regression
The line of best fit is the straight line that makes the squared vertical distances to your points as small as possible. Its slope tells you how much y changes for each one-unit increase in x. The intercept is the predicted y when x is zero.
Correlation r and R²
The correlation coefficient r runs from −1 to 1. Values near 1 or −1 mean the points hug a line, and values near 0 mean there is little straight-line pattern. R² is r squared and shows the share of the variation in y that the line explains.
Predicting values
Enter an x value to get the predicted y. Predictions inside the range of your data (interpolation) are more reliable than ones outside it (extrapolation), where the pattern may not continue.
Things to watch for
A high R² does not prove that x causes y. Outliers can pull the line a long way, and a curved pattern will fit a straight line poorly even if r looks decent. Always look at the plot.
Worked example
For the points (1, 2), (2, 4), (3, 5), (4, 4), (5, 5): the means are x̄ = 3 and ȳ = 4. Σ(x − x̄)(y − ȳ) = 6 and Σ(x − x̄)² = 10, so the slope is b = 6 ÷ 10 = 0.6 and the intercept is a = ȳ − b·x̄ = 4 − 1.8 = 2.2. The line is ŷ = 2.2 + 0.6x.
With Σ(y − ȳ)² = 6, the correlation is r = 6 ÷ √(10 × 6) = 0.775, and R² = 0.60: the line explains 60% of the variation in y. The predicted value at x = 6 is 2.2 + 0.6 × 6 = 5.8.
Frequently asked questions
What is the difference between r and R²?
r (from −1 to 1) gives the direction and strength of a linear relationship. R² (from 0 to 1) is the fraction of the variation in y explained by the line. For simple linear regression, R² = r².
Does a high r mean x causes y?
No. Correlation shows that two variables move together, not why. A third variable or coincidence can produce a strong correlation.
Can I predict outside my data range?
That’s extrapolation, and it’s risky: the relationship may not stay linear beyond the values you measured. Predictions inside the data range (interpolation) are much safer.
What is a residual?
The actual y minus the predicted ŷ for a data point. Least squares regression picks the line that makes the sum of the squared residuals as small as possible.