Enter your paired data below to find the best-fit regression line in the form y = mx + b, along with correlation and model fit metrics.
What this linear regression line calculator does
This calculator estimates a straight-line relationship between two variables. If you have data points such as study hours and test scores, ad spend and revenue, or temperature and energy usage, linear regression helps you model the trend.
The output is the best-fit line:
y = mx + b
- m is the slope (how much y changes when x increases by 1)
- b is the intercept (the estimated y when x = 0)
- r is the correlation coefficient (strength and direction of linear relationship)
- R² is the coefficient of determination (how much of y’s variation is explained by x)
How to use the calculator
Step 1: Enter your X values
Add all x-values in order. You can separate values by commas, spaces, or line breaks.
Step 2: Enter matching Y values
Each y-value must correspond to the x-value in the same position. The number of x and y values must match exactly.
Step 3: Click calculate
The tool computes slope, intercept, correlation, R², and error metrics. It also displays a small table with predicted values and residuals.
Step 4: Optional prediction
If you provide a single x value in the prediction field, the calculator estimates the corresponding y using your fitted line.
Core formulas used
The calculator uses ordinary least squares (OLS) for a simple linear model:
- Slope:
m = (nΣxy - ΣxΣy) / (nΣx² - (Σx)²) - Intercept:
b = (Σy - mΣx) / n - Correlation:
r = (nΣxy - ΣxΣy) / √[(nΣx²-(Σx)²)(nΣy²-(Σy)²)] - Coefficient of determination:
R² = r²
These formulas minimize the sum of squared residuals, giving you the line that best matches your data in a least-squares sense.
How to interpret your results
Slope (m)
If slope is positive, y tends to increase as x increases. If negative, y tends to decrease. A slope of 2 means each +1 in x is associated with about +2 in y on average.
Intercept (b)
The intercept is where the line crosses the y-axis. It can be useful, but only if x = 0 is meaningful in your context.
R and R²
Values of |r| close to 1 indicate a strong linear relationship. R² tells you how much variation in y is explained by x. For example, R² = 0.81 means about 81% is explained by the linear model.
Residuals and model error
Residuals are actual minus predicted values. Smaller residuals generally indicate a better fit. Look for patterns; strong patterns in residuals can mean a non-linear model might work better.
Common mistakes to avoid
- Using mismatched data lengths between X and Y
- Including non-numeric values or extra separators
- Assuming correlation implies causation
- Extrapolating far beyond the observed x-range
- Forgetting to check for outliers that can distort slope and intercept
When linear regression is useful
Simple linear regression is a practical starting point for forecasting and trend analysis in business analytics, education, health metrics, finance, and engineering. It’s quick, interpretable, and often surprisingly effective for first-pass modeling.