Statistics

Linear Regression Calculator

Fit a least-squares regression line to two data sets and predict new values.

Formula and sources updated · Data sources · 1View algorithm, constants and default inputs (JSON)

Enter your values

Slope 1.990000
Results

Results

ResultsPrediction outside the observed X range (extrapolation). / Slope: 1.9900 · Intercept: 0.0500 / Predicted value: 11.99; X values (comma separated): 6.00 / X values (comma separated): 1.00; Y values (comma separated): 2.10 / X values (comma separated): 2.00; Y values (comma separated): 3.90 / X values (comma separated): 3.00; Y values (comma separated): 6.20 / X values (comma separated): 4.00; Y values (comma separated): 7.80 / X values (comma separated): 5.00; Y values (comma separated): 10.10Y values (comma separated)1.05.09.013.0146X values (comma separated)Predicted value: 11.99 (6.00)Slope: 1.9900 · Intercept: 0.0500Prediction outside the observed X range (extrapolation).

About this calculator

Least-squares regression finds the straight line that minimises the total squared distance to the data points. It is the standard way to describe a linear relationship and to extrapolate a trend.

Worked example

calculated with the default values below

X values (comma separated) 1, 2, 3, 4, 5 · Y values (comma separated) 2.1, 3.9, 6.2, 7.8, 10.1 · Predict Y at X = 6 Slope 1.990000 · Intercept 0.050000 · R squared 0.9973 · Predicted value 11.990000 · Correlation 0.9987

Method and assumptions

b = Sxy ÷ Sxx; a = my − b × mx; r = Sxy ÷ √(Sxx × Syy); ŷ = b × x + a Pair values by position. X and Y need equal lists with at least two finite values; X must vary. Correlation and R² are undefined when Y is constant. Least-squares regression finds the straight line that minimises the total squared distance to the data points. It is the standard way to describe a linear relationship and to extrapolate a trend. The references explain definitions and methods; any extra preset must be checked against the assumptions on this page.

Data sources

The references explain definitions and methods; any extra preset must be checked against the assumptions on this page.

Disclaimer

These calculators give general mathematical results. They suit study, planning and estimation — verify anything that feeds a graded submission, a published figure or a financial commitment.

Maintained by: CalcDelta Formula and sources updated ·

Implementation source

This record describes the implementation used by this page. It is not independent validation. External references, when available, support only the stated formula or definition; estimates and custom rules retain their own assumptions.

View algorithm, constants and default inputs (JSON)

Formula and variables

b = Sxy ÷ Sxx; a = my − b × mx; r = Sxy ÷ √(Sxx × Syy); ŷ = b × x + a

x, y
paired sample values
mx, my
sample means
Sxx
Σ (x − mx)²
Sxy
Σ (x − mx)(y − my)
b, a
slope and intercept
r
Pearson correlation; r² is R²

Pair values by position. X and Y need equal lists with at least two finite values; X must vary. Correlation and R² are undefined when Y is constant.

Embed this calculator

Copy the iframe snippet to place this calculator on your site. No account required. The snippet stays in sync with the inputs currently shown.

Frequently asked questions

Why is the predicted Y at X=6 nearly 12 here?

Least-squares fits the line minimizing squared errors, giving this data a slope near 1.99 and intercept near 0.05, so Y is about 0.05 plus 1.99X. At X equals 6 the model predicts about 11.99. The R squared is close to 1 because the five points sit nearly on the fitted line. More scatter lowers R squared, but this calculator does not calculate a prediction interval or prediction uncertainty. Predictions beyond the observed X range are extrapolations and may be unreliable.

How should I enter paired data?

Enter the same number of comma- or space-separated X and Y values. Values pair by position. The calculator rejects unequal list lengths or invalid entries rather than silently removing a value and shifting later pairs.

Which inputs and limits apply to Linear Regression Calculator?

Use the units shown beside each field. These are form limits, not recommended settings. Predict Y at X =: -1,000,000,000,000–1,000,000,000,000 b = Sxy ÷ Sxx; a = my − b × mx; r = Sxy ÷ √(Sxx × Syy); ŷ = b × x + a Pair values by position. X and Y need equal lists with at least two finite values; X must vary. Correlation and R² are undefined when Y is constant. Least-squares regression finds the straight line that minimises the total squared distance to the data points. It is the standard way to describe a linear relationship and to extrapolate a trend. The references explain definitions and methods; any extra preset must be checked against the assumptions on this page.

What is a complete worked example for X values (comma separated) = 1, 2, 3, 4, 5; Y values (comma separated) = 2.1, 3.9, 6.2, 7.8, 10.1?

Inputs: X values (comma separated) = 1, 2, 3, 4, 5; Y values (comma separated) = 2.1, 3.9, 6.2, 7.8, 10.1; Predict Y at X = = 6. Calculation: b = Sxy ÷ Sxx; a = my − b × mx; r = Sxy ÷ √(Sxx × Syy); ŷ = b × x + a. Results: Slope = 1.990000; Intercept = 0.050000; R squared = 0.9973; Predicted value = 11.990000; Correlation = 0.9987.