About this linear regression calculator
Simple linear regression finds the straight line that best describes how a variable y changes with a variable x. Paste your paired data and this calculator returns the least-squares line y = a + bx, the slope and intercept, the correlation coefficient r, the coefficient of determination R², the standard error, and a p-value for the slope that tests whether the relationship is statistically different from zero. It also draws a scatter plot with the fitted line and predicts y for any x you enter.
The formulas
| Quantity | Formula |
|---|---|
| Slope (b) | b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² |
| Intercept (a) | a = ȳ − b x̄ |
| Correlation (r) | r = Sxy / √(Sxx Syy) |
| R² | r², the share of the variation in y explained by x |
| Standard error of estimate | s = √(SSE / (n − 2)) |
| t statistic for the slope | t = b / SE(b), with n − 2 degrees of freedom |
How to read the output
- Slope: the predicted change in y for each one-unit increase in x.
- Intercept: the predicted y when x is 0. It may not be meaningful if x = 0 is outside your data.
- r: from −1 to +1. Values near ±1 mean a strong straight-line pattern, and values near 0 mean little linear relationship.
- R²: r squared, so r = 0.9 gives R² = 0.81, meaning about 81% of the variation in y is explained by the line.
- p-value: the chance of a slope this large if the true slope were zero. A small value suggests a real linear trend.
Worked example
For the sample data (1, 2.1), (2, 3.9), (3, 6.2), (4, 7.8), (5, 10.1), the slope is about 1.99 and the intercept about 0.05, giving y = 0.05 + 1.99x with r very close to 1. Predicting x = 6 gives y ≈ 12.
Cautions
- Correlation is not causation. A strong fit does not show that x causes y.
- Check the scatter plot. A curve, an outlier or separate clusters can give a misleading r.
- Avoid extrapolating far beyond the range of your x values.
- You need at least 3 points for a p-value and standard error, and the x values must not all be the same.
Related tools: summarize each column with the Standard Deviation Calculator, check significance with the P-Value Calculator, or work with percent differences in the Percent Change Calculator.
Frequently asked questions
Use least squares: the slope is the sum of the products of x and y deviations from their means divided by the sum of squared x deviations, and the intercept is the mean of y minus the slope times the mean of x. This calculator does all of that when you paste your data.
It measures how closely the points follow a straight line, from -1 for a perfect downward line to +1 for a perfect upward line. A value near 0 means little linear relationship, although a curved relationship could still exist.
R-squared is r squared. It is the proportion of the variation in y that the straight-line model explains. An R-squared of 0.72 means the line accounts for about 72% of the variation.
You need at least 2 points to draw a line and at least 3 to get a standard error and a p-value. More points make the estimate more reliable, and the x values must not all be identical.
Yes. Enter an x value in the prediction box to read the predicted y from the fitted line. Predictions are most reliable inside the range of your data and less reliable far outside it.
Correlation gives a single number for the strength and direction of a linear relationship. Regression goes further by giving the equation of the line so you can predict one variable from the other.