
Linear Regression
Best-fit line (slope, intercept), correlation and R² from x/y data.
Best-fit line
y = 0.8x + 1.8
R² = 0.7273
Slope
0.8
Intercept
1.8
Correlation r
0.8528
AI Breakdown & Smart Takeaway
Plain-English insight on your numbers
Get a personalized explanation of what these results mean — and how to improve them.
How the Linear Regression works
This linear regression calculator finds the best-fit line through your x/y data pairs, instantly computing the slope, y-intercept, Pearson correlation coefficient, and R² so you can quantify relationships and make predictions — ideal for students, researchers, analysts, and anyone exploring data trends.
Linear regression works by finding the straight line that minimizes the total squared vertical distance between each data point and the line itself — a technique formally known as ordinary least squares (OLS). Rather than eyeballing a trend, OLS produces the unique line where no other placement could reduce the sum of those squared errors further. The result is expressed as ŷ = a + bx, where 'b' is the slope and 'a' is the y-intercept, giving you a precise, reproducible model of your data's linear trend.
The slope (b) tells you how much the y-variable is expected to change for every one-unit increase in x. A positive slope signals a direct relationship — as x rises, so does y — while a negative slope indicates an inverse relationship. The intercept (a) is the predicted value of y when x equals zero, which is mathematically necessary but may or may not be practically meaningful depending on your data's context. Both values are derived simultaneously using the formulas b = Σ[(xᵢ − x̄)(yᵢ − ȳ)] / Σ[(xᵢ − x̄)²] and a = ȳ − b·x̄.
The Pearson correlation coefficient (r) measures the strength and direction of the linear relationship on a scale from −1 to +1. Values near ±1 indicate a tight linear fit, while values near 0 suggest little to no linear association. R² (the coefficient of determination) is simply r squared, and it represents the proportion of variance in y that is explained by x — for example, an R² of 0.85 means 85% of the variability in your outcome is accounted for by your predictor. These two metrics together let you judge not just the direction of the trend but how reliably the line actually fits your data.
A common mistake is assuming a high R² proves causation — it only confirms that a linear pattern exists in your sample. Outliers have a disproportionate influence on least squares estimates because errors are squared before summing, so a single extreme point can dramatically shift the slope and inflate or deflate R². Always inspect a scatter plot of your data before trusting the regression output; if the relationship looks curved, a linear model will underfit and the residuals will show a systematic pattern. Also ensure your x-values span a meaningful range — extrapolating the best-fit line far beyond your observed data points leads to unreliable predictions.
Formula
slope = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²)
Pro tips
- Always visualize your data on a scatter plot before interpreting regression results — a perfect R² can still hide a non-linear relationship that a straight line fails to capture.
- If your R² is high but your slope is not statistically significant (check p-values in a full stats package), you may simply have too few data points for the result to be reliable.
- Scale matters: if your x-values span orders of magnitude (e.g., 1 to 1,000,000), consider log-transforming one or both variables before running the regression to linearize the relationship.
- Remove or investigate extreme outliers before finalizing your model — because least squares squares the errors, a single outlier can move the slope far more than its real-world importance warrants.
- Use the regression equation for interpolation (predicting within your data range) cautiously, and avoid extrapolation beyond your observed x-values unless you have strong theoretical reasons to believe the linear trend continues.
Key terms
- Least Squares
- — A method of fitting a line that minimizes the sum of the squared differences (residuals) between each observed y-value and the y-value predicted by the line.
- Slope (b)
- — The rate of change in the dependent variable (y) for each one-unit increase in the independent variable (x) along the best-fit line.
- Y-Intercept (a)
- — The predicted value of y when x equals zero; it sets the vertical position of the regression line on the graph.
- Pearson Correlation Coefficient (r)
- — A value between −1 and +1 that measures how strongly and in what direction two variables are linearly related.
- R² (Coefficient of Determination)
- — The square of the correlation coefficient, expressing the proportion of variance in y that is statistically explained by the linear regression model.
- Residual
- — The difference between an observed y-value and the y-value predicted by the best-fit line for the same x, used to assess how well the model fits each point.