Statistics and data

Linear Regression Calculator

Fit a straight line to paired X and Y values. See its slope, intercept, fit statistics, and an optional fitted value at your chosen X.

Fit a least-squares line with an intercept

Enter one number per line. X row 1 pairs with Y row 1, and so on. Commas group thousands: 1,000 means one thousand. Surrounding blank lines are ignored; blank rows inside a list are rejected.

2–100 pairs; up to 15 integer digits and 10 decimal places per number.

Leave blank to fit the line only. Use the same unit as your X list.

Fitted regression line

Enter your paired values, then select Calculate.

Enter adds a new line in either list. Press Ctrl+Enter or Command+Enter to calculate, or select Calculate. Calculations run in your browser; successful summaries appear in this tab's Recent calculations.

Formulas and worked examples

Ordinary least squares chooses the slope b and intercept a to minimize the sum of squared vertical residuals. A residual is an observed Y minus its fitted value ŷ.

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

SSE = Σ(y − ŷ)²
SST = Σ(y − ȳ)²
r² = 1 − SSE ÷ SST, when SST > 0

Worked example

Five paired observations

X: 1, 2, 3, 4, 5
Y: 2, 4, 5, 4, 5

The means are 3 and 4. The centered cross-products sum to 6 and the X squared deviations sum to 10.

b = 6 ÷ 10 = 0.6
a = 4 − 0.6 × 3 = 2.2
ŷ = 0.6x + 2.2

SSE = 2.4, SST = 6, and r² = 0.6. At X = 6, fitted Y = 5.8. Since 6 exceeds the observed range 1–5, this is extrapolation.

Negative slope

An exact falling line

X: 1, 2, 3
Y: 6, 4, 2

ŷ = −2x + 8
SSE = 0 · r² = 1

Every observed point lies on the line. At X = 2.5, fitted Y = 3; this X is within the observed range.

Constant response

A valid horizontal line

X: 1, 2, 3
Y: 7, 7, 7

ŷ = 0x + 7
SSE = 0 · SST = 0

The slope is zero and every fitted value is 7. r² is undefined because its formula divides by zero; it is not assigned 0 or 1.

Read the results in context

The slope describes fitted Y change per one X unit. The intercept is fitted Y at X = 0, which may fall outside the data or lack a useful real-world interpretation. The intercept and predictions use Y units; SSE and SST use squared Y units.

For this regression with an intercept and nonconstant Y, r² is the fraction of observed Y variation accounted for by the fitted line. It is unitless and equals squared Pearson correlation. A high r² does not establish causation or guarantee useful predictions. Inspect the observations and residual pattern when deciding whether a line is appropriate.

With two pairs and distinct X values, a line fits both points exactly. This leaves no additional observations to assess its residual variation. The calculator does not report confidence intervals, prediction intervals, p-values, or statistical significance.

Exact calculations and final rounding

Decimal data, coefficients, sums of squares, and fitted values are retained as exact fractions until display. Predictions use the original coefficients, so substituting the rounded equation by hand can give a different rounded answer.

Choose 0, 2, 4, 6, or 10 decimal places; the default is 6. Exact halfway values round away from zero. The ≈ symbol identifies changed values, with notes for small nonzero slopes, intercepts, SSE, and predictions that round to zero. A displayed r² of 1 may be rounded, so the tool distinguishes it from an exact fit. Range comparisons use unrounded X values.

References: NIST — Least Squares explains parameter fitting. Penn State — Simple Linear Regression explains sums of squares and the coefficient of determination. NIST — Linear Least Squares Regression discusses sensitivity to outliers and extrapolation.

Common questions

Can I paste columns from a spreadsheet?

Yes. Paste one numeric column into X and its paired column into Y, without headers or units. Use one number per line. Surrounding blank lines are ignored; a blank row inside a list is rejected so values cannot silently shift into different pairs. Do not sort just one column.

Does a comma separate two values?

No. Commas group thousands, so 1,000 is one value. Separate observations with new lines and use a period for decimals. Lists such as 1,2,3 are rejected.

Why must X values vary?

If every X is identical, the denominator of the slope formula is zero. Many slope and intercept combinations can give the same fitted value at that X, so there is no unique fitted line. Repeated X values are allowed as long as at least two distinct X values are present.

What happens when every Y is equal?

With varying X, the fitted line is horizontal at that Y value. Its predictions and coefficients are valid. Both SSE and SST are zero, so r² is undefined under the displayed formula.

Can the fitted line be forced through zero?

This calculator always estimates an intercept and fits one predictor with equal weights. It does not offer regression through the origin, multiple regression, weighted regression, or nonlinear curves; those methods use different assumptions and formulas.

What are the input limits?

Enter 2–100 paired observations, up to 6,600 characters per list and 64 characters per numeric entry. Numbers accept up to 15 integer digits and 10 decimal digits, with an optional keyboard plus or minus sign. Zero, negative values, and repeated pairs are allowed. Use a leading zero for 0.5; fractions, expressions, scientific notation, NaN, and Infinity are rejected. The optional prediction X uses the same numeric limits.