Linear Regression Calculator

Fit a straight line to paired observations and see what it explains—and what it misses. Explore the fitted equation, residuals and a prediction at your chosen X. Compare uncertainty in the mean response with the wider interval for one new observation, then export your inputs and results.

Linear regression workspace

See the fit and what it misses

Try a data set

Paired observations

Enter 2–500 X/Y pairs in consistent units. Every row is used; blanks and malformed values are errors.

Paste two columns

One pair per line; separate X and Y with a comma, tab or spaces. Semicolons may separate rows. No header, quoted CSV or thousands separators.

Observation 1
Observation 2
Observation 3
Observation 4
Observation 5

Prediction and uncertainty

The mean interval estimates an average response at this X. The wider prediction interval concerns one new observation. Both assume a suitable linear model with independent, normally distributed errors of constant variance.

Predicted mean response

4

At X = 3; fitted from 5 observations.

Slope
0.6
R²
0.6
Residual standard deviation
0.894427
Intercept
2.2

5 pairs. Predicted mean 4 at X 3.

Intervals at the selected X

95% Mean-response confidence interval

2.72702 to 5.27298

Half-width: 1.27298 Y units

95% New-observation prediction interval

0.881852 to 7.11815

Half-width: 3.11815 Y units

These are pointwise intervals, not a simultaneous band for every possible X. Endpoints are shortened when their width is preserved; full model values are in Fit statistics and CSV. Extra digits do not imply measurement precision.

Outlined row 1: X 1, observed Y 2, fitted Y 2.8, residual -0.8, leverage 0.6. Leverage measures how far an X lies from the center of the observed X values; it is not a reason to discard a row.

Observations and fitted line

Circles are entered observations; the solid line is the fitted mean response. The shaded region shows pointwise 95% mean-response confidence intervals.

Scatterplot and least-squares fitted lineThe plot contains 5 observations. Slope 0.6; intercept 2.2. The outlined observation is row 1. Exact entered values and fitted values are available in the ledger below. 0.05040.722.031.86435.974.147.955.28X

Vertical axis: Y. The line is drawn only across the observed X range.

What the line misses

Residuals are observed Y minus fitted Y. Curves, clusters or changing spread can reveal a poor fit.

Regression residual plotThe plot contains 5 observations. Residual standard deviation: 0.894427. The outlined observation is row 1. Exact entered values and fitted values are available in the ledger below. -0.9440.72-0.4221.860.130.6224.141.145.28X

Vertical axis: Residual (observed − fitted). The dashed line marks zero residual.

Fit statistics and numerical details
Pairs
5
Residual degrees of freedom
3
SSE
2.4
RMSE (divisor n)
0.69282
MSE (divisor n − 2)
0.8
Pearson r
0.774597
Mean X
3
Mean Y
4
Student-t critical value
3.18245

Interval endpoints at full model precision

Mean-response confidence interval
2.727021477886501 to 5.272978522113499
New-observation prediction interval
0.8818521672996953 to 7.1181478327003047

Decimal moments, the fitted line and residuals are calculated as rational numbers before square roots and Student-t computation. The original inputs are retained in the ledger and CSV. Scientific notation preserves small nonzero results.

Observed, fitted and residual values

Every entered observation, fitted mean, residual and leverage; no rows removed.
RowEntered XEntered YFitted YResidualLeverage
1122.8-0.80.6
2243.40.60.3
335410.2
4444.6-0.60.3
5555.2-0.20.6
View CSV text
Method, assumptions and sources

This is ordinary least squares with an intercept and one predictor. It minimizes the sum of squared vertical residuals. All observations receive equal weight. The calculator does not remove outliers, model measurement error in X, or establish causality.

Pointwise intervals use Student’s t with n − 2 degrees of freedom. Their interpretation depends on a linear mean relationship and independent, normally distributed errors of constant variance. A residual plot can reveal problems but cannot prove these assumptions.

Enter decimal or scientific-notation numbers with at most 48 characters, an exponent from −12 to 12, an absolute value at most 10¹², and at most 12 effective decimal places after trailing zeros are removed. Fractions, expressions, headers and thousands separators are not supported. Data remain in this page; export only when you choose.

How to use this calculator

  1. Enter paired X and Y observations in consistent units, or expand Paste two columns and apply comma-, tab- or whitespace-separated numeric pairs. The import has no header and does not silently discard invalid rows.
  2. Add or remove observations as needed. The model accepts 2–500 complete pairs, and every entered row receives equal weight.
  3. Enter Predict Y at X and choose a 90%, 95% or 99% confidence level. Read the mean-response confidence interval separately from the new-observation prediction interval.
  4. Compare the scatterplot with the residual plot. Change the scatterplot interval display and use Inspect an observation to highlight its fitted value, residual and leverage.
  5. Review fit statistics and the complete row ledger. Download CSV or expand View CSV text to select and copy the same results if downloads are blocked.

The Formula

The mathematical logic powering this calculation is:

For n paired observations, Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ).
Slope b = Sxy/Sxx; intercept a = ȳ − bx̄; fitted value ŷ = a + bx.
Residual e = y − ŷ; SSE = Σe²; RMSE = √(SSE/n). For n > 2, MSE = SSE/(n − 2) and residual standard deviation s = √MSE.
At x₀, h₀ = 1/n + (x₀ − x̄)²/Sxx.
Mean-response interval: ŷ₀ ± t(1 − α/2, n − 2) × s√h₀.
New-observation interval: ŷ₀ ± t(1 − α/2, n − 2) × s√(1 + h₀).
R² = Sxy²/(SxxSyy), undefined when Y is constant. These are pointwise intervals under the stated regression assumptions.

Worked Example

If you input:

  • Paired observations: 1,2; 2,4; 3,5; 4,4; 5,5
  • Predict Y at X: 3
  • Confidence level: 95%

Result:

The fitted line is ŷ = 2.2 + 0.6x. At X = 3, the predicted mean is 4. The five observations have SSE = 2.4 and R² = 0.6. The 95% mean-response interval is approximately 2.7270 to 5.2730; the new-observation interval is approximately 0.8819 to 7.1181.

Frequently Asked Questions

How is linear regression different from correlation?

Correlation summarizes the direction and strength of a linear association. This calculator also estimates a slope and intercept, fits Y values, computes residuals, and predicts a response at an entered X. It uses one predictor, an intercept and equal observation weights. Neither correlation nor regression establishes causation.

Why is the prediction interval wider than the confidence interval?

The confidence interval concerns the average response at a fixed X. A new observation also has its own random variation around that average, so its prediction standard error includes an additional MSE term. Both use Student’s t with n − 2 degrees of freedom and require a suitable linear relationship with independent, normally distributed errors of constant variance. The displayed intervals are pointwise, not a simultaneous guarantee across all X values.

What do residuals and leverage tell me?

A residual is observed Y minus fitted Y. Curvature, clusters or changing spread in residuals can reveal problems that a large R² hides. Leverage depends on an observation’s X position relative to the other X values and helps identify points that can strongly affect a fitted line. The calculator keeps all rows; it never labels a point for automatic deletion.

What happens with two points or constant data?

Two distinct X values determine a line, but two observations leave no residual degrees of freedom. The fit and residual ledger remain available while MSE, residual standard deviation and Student-t intervals are unavailable. If all X values are equal, an intercept-plus-slope fit is not identifiable. If Y is constant, the horizontal line is valid but correlation and R² are undefined. Exact zero SSE with at least three observations produces degenerate model intervals; it does not establish certainty about future data.

Can I predict outside the observed X range?

Yes, within the supported input range, but the result is explicitly labeled extrapolation. The fitted line may no longer describe the process beyond the observed data. A calculated interval reflects the assumed linear model and its estimated residual variance; it does not account for an unknown change in the relationship.

How are large offsets and small differences handled?

Entered decimal coordinates are retained as text and converted to exact rational numbers for centered moments, coefficients, fitted values and residuals. Differences for plots are calculated before floating-point conversion, so a large common offset does not erase a small spread. Square roots and Student-t quantiles are numerical approximations. Interval half-widths and adaptive decimal endpoint text preserve narrow intervals even if binary64 endpoint numbers coincide. Extra digits describe the calculation, not the precision of measurements.

Which inputs and paste formats are accepted?

Enter 2–500 X/Y pairs. A value may have at most 48 characters, absolute value at most 10¹², an exponent from −12 to 12, and at most 12 effective decimal places after trailing zeros are removed. Decimal and scientific notation are supported; fractions, formulas, headers, quoted CSV and thousands separators are not. Paste uses one pair per line or semicolon-separated row, with a comma, tab or spaces between the two values. Empty internal rows and invalid cells reject the whole import while preserving the current data.

What does the CSV contain?

The CSV includes the original entered X/Y strings, fitted values, residuals, leverage, exact-origin plot offsets, fit statistics and the selected prediction’s interval endpoints and half-widths. Undefined or unestimable quantities are labeled unavailable rather than replaced with zero. The selectable CSV text is the same content used for the requested download.

Similar Calculators