Math · Statistics

Linear regression calculator.

Paste your x and y pairs to fit the least-squares line, see it on a scatter plot and predict y for a new x. Your data stays in this browser.

For OpenStax's 11 pairs of third-exam (x) and final-exam (y) scores the least-squares line is y = −173.51 + 4.83x, with R² = 0.4397. Each extra point on the third exam goes with about 4.83 more points on the final.

b = Sxy / Sxxa = ȳ − b x̄Opened sources 8 October 2026

The formulas

The least-squares line ŷ = a + bx has slope b = Sxy / Sxx and intercept a = ȳ − b x̄, where Sxy = Σ(x − x̄)(y − ȳ) and Sxx = Σ(x − x̄)². R² is the square of the correlation coefficient. The residual standard error is s = √(SSE / (n − 2)) and the standard error of the slope is s / √Sxx. The ratio t = b / SE(b) follows a Student’s t distribution with n − 2 degrees of freedom, which gives the p-value for the slope.

Worked example

The default data are the OpenStax third-exam versus final-exam example. OpenStax gives the line ŷ = −173.51 + 4.83x, r = 0.6631 and r² = 0.4397. This calculator returns slope 4.8274, intercept −173.5134, r = 0.6631 and R² = 0.4397, which round to the same equation. Predicting at x = 70 gives −173.5134 + 4.8274 × 70 = 164.40. (Using the rounded equation, −173.51 + 4.83 × 70 = 164.59, so tiny differences are rounding.) The slope’s t statistic is 2.6576 on 9 degrees of freedom, p = 0.0262.

Limits

Regression describes a straight-line trend in your data. Predicting for x values outside the range you observed (extrapolating) can be badly wrong, and a high R² does not prove cause. The p-value assumes independent observations, a roughly linear relationship, and errors of similar size across x that are roughly normal. Look at the scatter plot before trusting the line.

Sources, opened 8 October 2026: OpenStax Introductory Statistics 2e, 12.3 The Regression Equation (the third-exam and final-exam data, ŷ = −173.51 + 4.83x, r = 0.6631, r² = 0.4397); Wikipedia, Simple linear regression (the slope t-value has a Student’s t distribution with n − 2 degrees of freedom).

Frequently asked questions

How do you calculate a linear regression line?

Find the slope b = S_xy / S_xx from the deviations of x and y around their means, then the intercept a = mean of y - b x mean of x. The line is y = a + b x.

What is the regression line for the OpenStax exam example?

y = -173.51 + 4.83x, with r = 0.6631 and R squared = 0.4397. This calculator returns slope 4.8274 and intercept -173.5134, which round to the same equation.

What does R squared mean here?

R squared is the share of the variation in y that the straight line accounts for. In the example it is 0.4397, so about 44% of the variation in final-exam scores goes with the third-exam score.

Why can the prediction differ from my textbook answer?

This calculator keeps every decimal of the slope and intercept. A textbook that rounds the equation to two decimals first will give a slightly different prediction. For x = 70 the unrounded answer is 164.40 and the rounded equation gives 164.59.

Is it safe to predict outside my data range?

It is risky. The line was fitted only where you have data, so predicting beyond the smallest or largest x assumes the same straight-line trend continues. The calculator warns you when you do this.

How many points do I need?

At least three pairs, because the residual standard error uses n - 2 degrees of freedom. More points make the slope estimate more stable.

Learning aid, not for decisions

Educational calculator. Results assume the conditions listed on this page, which real data often only roughly meet. Do not use it for clinical, regulatory, legal or financial decisions.

Advertisement
Advertisement