Linear Regression Calculator

Fit the best straight line through your data and make predictions.

Linear Regression Calculator tool

—
Regression line
—
Slope (b)
—
Intercept (a)
—
R²
—
Standard error of estimate
—
Prediction

About the Linear Regression Calculator

Linear regression fits the straight line that best describes a trend, so you can summarize a relationship and make predictions. This calculator fits the least-squares line to paired X and Y data and reports the slope, intercept, correlation and R²: for the points (1, 2), (2, 4), (3, 5), (4, 4) and (5, 5), the line is y = 2.2 + 0.6x. Residuals and predictions are shown too.

Least squares chooses the line that makes the sum of the squared vertical distances from the points to the line as small as possible. The slope is b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², and the line always passes through the point of means, so the intercept is a = ȳ − b x̄. R² is the share of the variation in Y that the line explains, and the residuals, actual minus predicted values, show where the line fits well and where it misses.

Example: for X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5, the fitted line is ŷ = 2.2 + 0.6x, with R² = 0.6. Each extra unit of X adds 0.6 to the predicted Y. At x = 6 the prediction is 2.2 + 0.6 × 6 = 5.8, though predictions beyond the range of the data, called extrapolation, should be treated with caution.

Regression assumes a roughly linear relationship with evenly scattered residuals. For the strength of the relationship alone use the correlation coefficient calculator; for the slope between two points, the slope calculator; and for the spread of each variable, the standard deviation calculator.

How to use the Linear Regression Calculator

  1. Enter the X valuesType or paste the independent variable.
  2. Enter the Y valuesType or paste the dependent variable in the same order.
  3. Read the equationSee ŷ = a + bx with the slope, intercept and R².
  4. Predict and checkEnter an X value for a prediction and review the residuals table.

Linear Regression Calculator features

  • Least-squares line ŷ = a + bx
  • Slope, intercept, r and R²
  • Standard error of the estimate
  • Predictions for any X
  • Residuals table, downloadable as CSV
  • Paste columns from spreadsheets
  • Formulas shown with your numbers

Common uses

  • Trend lines for sales, prices or growth
  • Science lab calibration curves
  • Economics and social science coursework
  • Forecasting from historical data
  • Checking spreadsheet trendlines

Linear regression in practice: predictions, slopes, residuals and extrapolation

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

Linear regression fits the straight line that best describes how one variable changes with another. Businesses use it to relate advertising to sales, scientists to relate dose to response and analysts to forecast trends. This guide works through an advertising example, explains what the slope and intercept mean in context, shows how to check a fit with residuals and warns against predicting far beyond the data.

The line of best fit

Least-squares regression chooses the line that minimises the total of the squared vertical distances between the points and the line. The result is written y = a + bx, where b is the slope, the change in y for each unit increase in x, and a is the intercept, the predicted y when x is zero. The fitted line summarises the average relationship; individual points scatter around it.

A worked example: advertising and sales

A shop records monthly advertising spending and sales, both in thousands of rupees: spending of 10, 15, 20, 25 and 30 brought sales of 110, 140, 145, 185 and 195. The regression line is sales = 69 + 4.3 × spending, and r² is about 0.95, so the line fits the data closely.

The slope means that, within this range, each extra thousand rupees of advertising has been associated with about 4,300 rupees of extra sales. Predicting for spending of 35 thousand gives about 219.5 thousand in sales, a modest step beyond the data. A prediction for 100 thousand, far outside the observed range, would not be trustworthy.

Interpreting the intercept

The intercept is the predicted value when x is zero, but that is not always meaningful. In the shop example, an intercept of 69 suggests sales of 69 thousand with no advertising, which is plausible, since some customers come anyway. For a regression of weight on height, an intercept at zero height makes no sense, and it is simply part of the line's equation rather than something to interpret.

Residuals

A residual is the difference between an actual value and the value predicted by the line. Plotting residuals against x is the best way to check a regression: they should scatter randomly around zero. A curved pattern suggests the relationship is not linear, and a funnel shape suggests the spread changes with x. Either pattern means the simple line may mislead.

The danger of extrapolation

Predictions inside the range of the data, called interpolation, are usually reasonable. Predictions far outside it, extrapolation, assume the relationship continues unchanged, which is often false. Advertising cannot increase sales without limit, plant growth slows as plants mature and trends in prices change direction. Treat extrapolated predictions with great caution.

Regression and causation

A regression line shows association, not necessarily cause. If the shop advertised more in months when demand was already rising, for example before Eid, the regression would credit advertising with sales that the season caused. Experiments, such as varying advertising at random, or including other variables in a multiple regression, help separate effects.

R² and its limits

R² measures how much of the variation in y the line explains, from 0 to 1. A high R² does not guarantee that the model is correct, and a low R² does not mean the relationship is useless; in noisy fields, a small but real effect can still be valuable. Look at the slope, its uncertainty and the residuals as well as R².

Common mistakes

  • Extrapolating far beyond the observed data.
  • Interpreting a meaningless intercept.
  • Ignoring curved patterns in the residuals.
  • Treating the regression slope as proof of cause.

Related tools

For the strength of the relationship, use Correlation Coefficient Calculator. For slopes between two points, try Slope Calculator, and for testing results, P-Value Calculator.

Regression in spreadsheets

Spreadsheets provide regression functions directly: =SLOPE(y_range, x_range) and =INTERCEPT(y_range, x_range) give the line's coefficients, =RSQ gives R², and =FORECAST.LINEAR(x, y_range, x_range) predicts a value. LINEST returns several statistics at once, including standard errors. Adding a trendline to a scatter chart shows the same line visually and can display its equation.

More than one predictor

Real outcomes usually depend on several factors. Multiple regression extends the method to include more than one predictor, such as advertising, season and price together. Each coefficient then estimates the effect of its variable while holding the others constant, which helps separate effects that simple regression would mix together. Multiple regression needs more data and care, especially when predictors are strongly related to each other.

Influential points

A single point far from the others in the x direction can pull the regression line towards itself, changing the slope dramatically. Such points are called influential. Check by fitting the line with and without the unusual point: if the slope changes a lot, report both results and investigate whether the point is an error, a special case or a sign that the relationship changes at extreme values.

Limits

The fit is exact for the data entered; predictions carry uncertainty, especially outside the data's range.

Frequently asked questions

What is linear regression?

A method for fitting a straight line to data to describe how one variable changes with another. The fitted line ŷ = a + bx can then predict Y for new values of X.

How is the slope calculated?

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², the covariance of X and Y divided by the variance of X. It tells you how much Y changes, on average, for each one-unit increase in X.

What does R² mean in regression?

The proportion of the variation in Y explained by the line, from 0 to 1. An R² of 0.85 means the line accounts for 85% of the variation; the rest is left in the residuals.

What is a residual?

The difference between an actual Y value and the value the line predicts for it. Positive residuals are points above the line and negative ones below. Least squares minimizes the sum of their squares.

Can I use the line to predict outside my data?

You can, but extrapolation is risky because the relationship may not stay linear beyond the observed range. Predictions within the range of your X values are much more reliable.

What is the standard error of the estimate?

The typical size of the residuals: √(Σ residual² ÷ (n − 2)). It is in the units of Y, so a value of 0.89 means predictions typically miss by about 0.89.

What is the difference between correlation and regression?

Correlation measures how strongly two variables move together, symmetrically. Regression fits a line to predict one variable from the other, so swapping X and Y gives a different line.

How do I do linear regression in Excel?

Use SLOPE and INTERCEPT on the Y and X ranges, RSQ for R², and FORECAST.LINEAR for predictions, or add a linear trendline to a scatter chart and display its equation. The results match this calculator.