Skip to content
MoneyDeck

Linear Regression Calculator

Fit a least-squares line of best fit and predict new y values

Updated · Free, no signup

Separate with commas, spaces or new lines.

Regression equation

ŷ = 2.2 + 0.6x

Slope (b)

0.6

Y-intercept (a)

2.2

Predicted y at chosen x

5.8

Correlation coefficient (r)

0.7746

R² (coefficient of determination)

0.6

Standard error of the estimate

0.8944

Number of pairs

5

  • Each 1-unit increase in x changes the predicted y by 0.6.
  • Strong positive fit: R² = 0.6 (60% of the variation in y is explained by x).
  • x = 6 is outside your data range (1 to 5), so this prediction is an extrapolation.

Data (sorted by x) and fitted regression line

Fitted values and residuals

xyFitted ŷResidual (y − ŷ)
122.8-0.8
243.40.6
3541
444.6-0.6
555.2-0.2

About the Linear Regression Calculator

This linear regression calculator finds the straight line that best fits a set of paired data using ordinary least squares. Paste your x and y values and it returns the regression equation ŷ = a + bx, the slope and intercept, the correlation coefficient r, R², the standard error of the estimate, and a predicted y for any x you choose.

It is useful for students learning simple linear regression, analysts forecasting sales from ad spend, scientists fitting calibration curves, and anyone who needs a trend line without opening a spreadsheet. The chart overlays the fitted line on your data, and the table lists each point’s predicted value and residual so you can spot outliers or curvature.

Values are paired by position. Predictions are most trustworthy inside the range of your x data; extrapolating far beyond it assumes the straight-line pattern continues, which is often not true.

How to use the linear regression calculator

  1. 1Enter the x (independent) values, separated by commas or new lines.
  2. 2Enter the matching y (dependent) values in the same order.
  3. 3Type an x value to get a prediction from the fitted line.
  4. 4Read the equation, slope, intercept and R².
  5. 5Check the residual table and chart for outliers or a curved pattern.

Formula and method

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² a = ȳ − b·x̄ ŷ = a + bx

Ordinary least squares chooses the slope b and intercept a that minimise the sum of squared vertical distances (residuals) between each observed y and the line. Setting the derivatives of that sum to zero gives the closed-form slope above, and the line always passes through the point of means (x̄, ȳ).

R² equals the square of Pearson’s r for simple regression and gives the fraction of the variance in y explained by the line. The standard error of the estimate is √(SSE ÷ (n − 2)), the typical size of a residual, using n − 2 because two parameters were estimated.

b
Slope: change in ŷ for a one-unit change in x
a
Intercept: predicted y when x = 0
x̄, ȳ
Means of x and y
SSE
Sum of squared residuals Σ(y − ŷ)²

Worked examples

Five-point textbook example

x̄ = 3 and ȳ = 4. Σ(x − x̄)(y − ȳ) = 6 and Σ(x − x̄)² = 10, so b = 0.6 and a = 4 − 0.6 × 3 = 2.2. At x = 6 the line predicts 2.2 + 3.6 = 5.8, and R² = 0.6.

Ad spend ($k) vs sales ($k)

Mean spend is 20 and mean sales 170. Σ(x − x̄)(y − ȳ) = 1,200 and Σ(x − x̄)² = 250, so each extra $1k of ads is associated with $4.8k more sales. The line predicts 74 + 4.8 × 35 = $242k at $35k spend — an extrapolation just beyond the data.

Negative slope: car age vs value

The fitted line ŷ = 32.6 − 3.1714x says the car loses about $3,170 of value per year (values in $k). At 4.5 years old it predicts roughly $18.3k.

Frequently asked questions

What is the line of best fit?+

It is the straight line that makes the sum of squared vertical distances between the data points and the line as small as possible. That least-squares line always passes through the mean of x and the mean of y.

How do I interpret the slope and intercept?+

The slope is the average change in y for each one-unit increase in x. The intercept is the predicted y when x is 0, which only has a practical meaning if x = 0 is within or near the range of your data.

What does R² tell me in regression?+

R² is the proportion of the variance in y explained by the regression line, from 0 to 1. An R² of 0.85 means 85% of the variation in y is accounted for by x; the remaining 15% is unexplained scatter.

What is a residual?+

A residual is the observed y minus the predicted ŷ for that point. Positive residuals are above the line, negative ones below. Patterns in residuals (a curve or a funnel shape) suggest a straight line is not the right model.

Is it safe to predict outside the range of my data?+

Extrapolation is risky because the relationship may change beyond the observed range. Predictions are most reliable for x values between your smallest and largest observed x.

How is regression different from correlation?+

Correlation measures how strongly two variables move together and is symmetric. Regression produces an equation that predicts y from x, and swapping x and y gives a different line.

Related tools