Skip to content

Simple linear regression calculator

Fit a least-squares line to paired X and Y values. See slope, intercept, R², predictions and residuals.

Paired data

Processed in your browser.

2–200 values. Separate with spaces, commas or semicolons. Decimal point: 1.5.

2–200 values. Separate with spaces, commas or semicolons. Decimal point: 1.5.

Leave blank to fit the line only.

Result

Enter two lists, then calculate.

How to use

  1. Enter the two lists in matching order: the first number in one list belongs with the first number in the other. Keep each list in one consistent unit and remove headings or unit symbols.
  2. Use spaces, commas or semicolons between numbers, and a dot for decimals, such as 1.5. A comma always starts another value, even when your display language uses decimal commas. Scientific notation such as 2e-3 is accepted.
  3. Results and charts update as soon as both lists are valid. Incomplete or mismatched input leaves the results empty. Press Calculate if you want to see an explanation of an input error.
  4. Copy results copies the numerical summary as text. Clear empties the inputs and results. The chart is an on-screen explanation; this tool does not export an image or data file.

Example

Which straight line best follows the points? The short vertical gaps are residuals: observed Y minus the fitted Y.

YX0213253

ŷ = a + bX · e = Y − ŷ

X: 1 2 3 · Y: 2 3 5

Slope = 1.5 · Intercept ≈ 0.33 · At X = 2, ŷ ≈ 3.33

The input fields start with this example. Edit them to use your own data, then calculate.

What the results mean

This calculator fits one straight line to paired numeric measurements. Use it to check a simple trend, verify a least-squares exercise, or estimate Y at a chosen X. It fits Y from X and includes an intercept. It does not fit multiple predictors, curved models or a line forced through the origin.

The model is ŷ = a + bX. With dx = X − mean(X) and dy = Y − mean(Y), the slope is b = Σ(dx × dy) / Σ(dx²), and a = mean(Y) − b × mean(X). The line minimizes the sum of squared vertical residuals. It does not minimize perpendicular distances to the line.

Slope measures the change in fitted Y for one additional unit of X. The intercept is the fitted Y at X = 0, which may be outside your data and have little practical meaning. R² is the fraction of centered Y variation explained by this fitted line; for this intercept model it equals Pearson r squared when Y varies.

The first chart connects every observed point to the line with a vertical residual segment. The second chart puts those same signed residuals around zero, using the same X scale. Curves, widening spread or isolated large residuals can reveal features the straight line misses. The line is drawn over the observed X range.

Worked examples

X = 1, 2, 3 and Y = 2, 4, 6 give slope 2, intercept 0 and R² = 1. At X = 4 the fitted prediction is 8. All residuals are zero. Because 4 is outside the observed range 1–3, the prediction is explicitly marked as extrapolation.

X = 1, 2, 3 and Y = 2, 3, 5 give b = 1.5, a ≈ 0.33 and R² ≈ 0.96. The fitted values are about 1.83, 3.33 and 4.83; residuals are about 0.17, −0.33 and 0.17. At X = 2 the prediction is approximately 3.33.

Input, precision and output

To predict a value, fill the optional X field before calculating; leave it empty when you only need the fitted relationship. Predictions use full internal coefficients, so manually substituting rounded displayed coefficients can differ slightly. Assess predictions on new observations when practical. A good fit on these data does not promise future accuracy, and extrapolation is especially uncertain.

Both lists need the same 2–200 values. Missing entries, text, NaN and infinity are rejected. Zero, negative numbers and repeated values are allowed. Remove a missing observation from both lists, rather than shifting only one list.

Nonzero input magnitudes must be between 1e-100 and 1e100. Calculations use browser floating-point numbers, with about 15–16 significant digits. Distinct entries that collapse to the same stored number are rejected; reduce an offset or choose more suitable units before retrying.

Most displayed results use at most two decimal places. Small nonzero values use scientific notation, and calculations keep unrounded intermediate values. Offset/scaled axes explicitly show how to recover the original values, so tiny differences remain visible beside a large baseline.

Frequently asked questions

Why can a constant X list not be fitted?

There is no horizontal variation, so the slope denominator is zero and a unique slope cannot be identified. Repeated X values are allowed as long as at least two distinct X values remain.

What happens when all Y values are equal?

The fitted line is horizontal with slope zero and the constant value as intercept. Residuals are zero, but R² is undefined because total Y variation is also zero; it is not reported as a perfect explanatory score.

Is the fit reliable with only two points?

Two distinct X values determine a line exactly. A zero residual and R² = 1 in this case are geometric consequences, not evidence of predictive reliability or a statistically significant effect.

Are confidence intervals or significance tests included?

No. This tool reports the fitted line and descriptive residuals, without p-values, confidence intervals or a guarantee of forecast performance. Swapping X and Y also changes the regression problem.