All Tools

Linear Regression Calculator

Enter paired data to find the best-fit line, correlation, and residuals. Drag the prediction point along the line to explore. All calculations run in your browser.

Tip: Press Ctrl+Enter (Cmd+Enter on Mac) to calculate.

Reference Guide

The Least Squares Method

The best-fit line minimizes the sum of squared differences between observed and predicted values.

Slope
m=nxiyixiyinxi2(xi)2m = \frac{n\sum x_i y_i - \sum x_i \sum y_i}{n\sum x_i^2 - (\sum x_i)^2}
Intercept
b=yˉmxˉb = \bar{y} - m\bar{x}

Correlation Coefficient (r) and R²

Pearson's r Measures the strength and direction of a linear relationship, from −1 to +1.
r=nxiyixiyi(nxi2(xi)2)(nyi2(yi)2)r = \frac{n\sum x_i y_i - \sum x_i \sum y_i}{\sqrt{(n\sum x_i^2 - (\sum x_i)^2)(n\sum y_i^2 - (\sum y_i)^2)}}
R² (Coefficient of Determination) The proportion of variance in y explained by x. Calculated as R2=r2R^2 = r^2.

Values above 0.7 suggest a strong relationship. Between 0.3 and 0.7 is moderate. Below 0.3 is weak.

Interpreting Slope and Intercept

Slope (m) For each one-unit increase in x, y is predicted to change by m units. A negative slope means y decreases as x increases.
Intercept (b) The predicted value of y when x is zero. Be careful interpreting this if x = 0 is outside your data range, since the model may not hold there.
Extrapolation warning Predictions beyond the range of your data (extrapolation) are less reliable than predictions within the range (interpolation).

Residuals and Model Assumptions

Residual The difference between the observed and predicted value.
ei=yiy^ie_i = y_i - \hat{y}_i
Residual plot Plot residuals against predicted values. If the linear model fits well, residuals should scatter randomly around zero with no visible pattern.
Warning signs A curved pattern suggests a nonlinear relationship. A funnel shape suggests unequal variance (heteroscedasticity). Both indicate the linear model may not be appropriate.