Linear Regression Calculator
StatisticsCalculate the simple linear regression line for paired X, Y data in seconds. Get the slope, intercept, and R² so you can predict Y from any new X value instantly.
Add up to 12 data points. At least 2 pairs are required.
Regression Line
Slope
0
Intercept
0
R²
0
Fit Quality
Based on 0 data points, this line explains 0.0% of the variance in Y. Use the equation above to predict Y for any new X value.
What is a Linear Regression?
The Linear Regression Calculator fits a straight-line equation (y = mx + b) through your paired X, Y data points using the least-squares method. Enter your data pairs, and the calculator returns the slope, intercept, and R² (goodness of fit), so you can predict Y for any new X value using the resulting equation.
Linear regression is the foundational technique for modeling and predicting relationships between two continuous variables. Whether you're forecasting sales from advertising spend, predicting exam performance from study hours, or estimating price from size, this calculator finds the best-fitting line through your data instantly and reports how well that line actually captures the relationship.
Before fitting a line, use the Correlation Coefficient Calculator with the same data to confirm a meaningful linear relationship exists — a very low correlation means a straight-line fit may not be the right tool for your data.
How to use this Linear Regression calculator
Enter your paired X, Y data points — each row represents one observation with both an X (predictor) and Y (outcome) value.
Add more pairs as needed — up to 12 data points can be entered; more data generally produces a more reliable fitted line.
Read the slope and intercept — these define your prediction equation y = mx + b.
Check R² — a higher R² (closer to 1) means the line explains more of the variation in your data and predictions can be trusted more.
Predict new values — plug any new X value into the displayed equation to estimate the corresponding Y, staying within the range of X values in your original data.
Confirm linearity first — if R² is low, check the Correlation Coefficient Calculator and consider whether your data actually follows a non-linear pattern instead.
Formula & Methodology
Slope: m = [nΣxy − ΣxΣy] / [nΣx² − (Σx)²] Intercept: b = (Σy − mΣx) / n Variable definitions: - x, y — individual paired data values - n — number of data pairs - Σ — sum across all data pairs Worked example: Advertising spend in $1000s (X) vs monthly sales in $1000s (Y): (1, 2.1), (2, 3.9), (3, 6.2), (4, 7.8), (5, 10.1) Step 1 — n = 5, Σx = 15, Σy = 30.1, Σxy = 112.5, Σx² = 55 Step 2 — Slope: m = (5×112.5 − 15×30.1) / (5×55 − 15²) = (562.5 − 451.5) / (275 − 225) = 111 / 50 = 2.22 Step 3 — Intercept: b = (30.1 − 2.22×15) / 5 = (30.1 − 33.3) / 5 = −0.64 Fitted equation: y = 2.22x − 0.64 This means each additional $1,000 in ad spend is associated with roughly $2,220 in additional monthly sales, based on this dataset. Assumption: Linear regression assumes the true relationship between X and Y is approximately linear across the range of your data. Predictions made far outside the range of your original X values (extrapolation) are unreliable, and the model does not account for other variables that may also influence Y.
Frequently Asked Questions