HomeCalculatorsStatisticsLinear Regression Calculator

Linear Regression Calculator

Statistics

Calculate 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.

Paired Data Points (X, Y)
XY#1#2#3#4#5

Add up to 12 data points. At least 2 pairs are required.

Regression Line

y = 0x + 0

Slope

0

Intercept

0

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

  1. Enter your paired X, Y data points — each row represents one observation with both an X (predictor) and Y (outcome) value.

  2. Add more pairs as needed — up to 12 data points can be entered; more data generally produces a more reliable fitted line.

  3. Read the slope and intercept — these define your prediction equation y = mx + b.

  4. 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.

  5. 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.

  6. 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

Simple linear regression fits a straight line (y = mx + b) through a set of paired X, Y data points, letting you predict a Y value for any given X. It finds the line that minimizes the total squared distance between the actual Y values and the line's predicted values — the 'least squares' method. For example, fitting a line through advertising spend (X) and sales (Y) data lets you estimate expected sales for a new spend level.
Slope (m) = [nΣxy − ΣxΣy] / [nΣx² − (Σx)²]. Once you have the slope, intercept (b) = (Σy − mΣx) / n. These formulas come from minimizing the sum of squared vertical distances between each data point and the fitted line — the 'least squares' criterion that defines linear regression.
The slope tells you how much Y is expected to change for every one-unit increase in X. A slope of 2.5 means that for every additional unit of X, Y increases by 2.5 units on average. A negative slope means Y decreases as X increases. The slope's units are always (Y units) per (X unit), which is essential for correctly interpreting the practical meaning of the number.
The intercept (b) is the predicted value of Y when X equals zero — where the fitted line crosses the Y-axis. It's only practically meaningful if X = 0 is a realistic or interpretable value in your data's context; for many real-world variables (like age or price), X = 0 falls outside the range of your actual data and the intercept should be treated as a mathematical artifact of the fitted line rather than a meaningful prediction.
R² (the coefficient of determination) ranges from 0 to 1 and tells you the proportion of variance in Y explained by the linear relationship with X. An R² of 0.85 means 85% of the variation in Y is explained by X's linear relationship, with the remaining 15% due to other factors or noise. There's no universal 'good' R² threshold — it depends heavily on your field; social science data often has lower R² than physical science data even for genuinely useful models.
Extrapolating beyond the range of X values you used to fit the line is risky — the linear relationship you observed may not hold outside that range, and predictions become increasingly unreliable the further you extrapolate. Always restrict predictions to within (or very close to) the range of X values actually present in your original dataset.
Correlation (r) measures the strength and direction of a linear relationship symmetrically, without designating either variable as the 'predictor.' Linear regression instead produces a specific equation for predicting Y from X, treating the two variables asymmetrically. Use the [Correlation Coefficient Calculator](/correlation-coefficient-calculator/) first to confirm a meaningful linear relationship exists, then use this calculator to build the actual prediction equation.
Linear regression fits the single best straight line through all data points collectively — individual points will typically fall above or below the line (these gaps are called 'residuals'). A low R² combined with visibly scattered points around the line suggests either the relationship isn't strongly linear, or other factors beyond X are meaningfully influencing Y.
At minimum, 2 points are needed to mathematically define a line, but at least 10-15 points are recommended for the fitted line to be a reasonably stable and trustworthy summary of the relationship, and 30 or more for higher confidence — especially if the data has meaningful scatter around the trend.
A slope near zero means changes in X have little to no linear effect on Y — the fitted line is nearly flat. This typically corresponds to a low R² as well, since a flat line explains little of Y's variation. It suggests X may not be a useful linear predictor of Y, though a non-linear relationship could still exist.
Common applications include forecasting sales based on advertising spend, predicting exam scores from study hours, estimating house prices from square footage, and modeling the relationship between temperature and energy consumption. In each case, the fitted equation (y = mx + b) provides a simple, interpretable prediction tool once a meaningful linear relationship has been confirmed.
Outliers are data points that fall unusually far from the general pattern of the rest of the data. Because least-squares regression minimizes squared distances, a single extreme outlier can disproportionately pull the fitted line toward it, distorting both the slope and R². Always inspect your data (ideally with a scatter plot) for outliers before trusting a regression result, and consider whether an outlier reflects a data entry error or a genuinely unusual observation worth investigating.
Also known as
linear regression calculatorregression line calculatorleast squares calculatorslope intercept calculatorbest fit line calculator