CHART CHOICES & CHECKABLE METHODS

Line of best fit: slope, intercept and residuals

An ordinary least-squares line with an intercept minimizes the sum of squared vertical residuals. Its slope is the centred cross-product sum divided by the centred X-square sum. It is a model summary of pairs, not a line joining them.

All chart guides →

The comparison at a glance

StepCalculation
Centred X squares42
Centred cross-products50
Slope50/42 = 25/21
Intercept9/14
Residual at (3,5)11/14

Reproduce the fitted coefficients

Our positive-association example has eight pairs, mean X = 4.5 and mean Y = 6. The sum of (X − 4.5)² is 42 and the sum of (X − 4.5)(Y − 6) is 50. The slope is 50/42 = 25/21, approximately 1.190476. The intercept is 6 − (25/21) × 4.5 = 9/14, approximately 0.642857.

Read a residual at one point

At X = 3, the fitted Y is (25/21) × 3 + 9/14 = 59/14, approximately 4.214286. The observed Y is 5, so the vertical residual is 11/14, approximately 0.785714. Squaring residuals prevents positive and negative deviations from cancelling in the fitting objective.

Know what the calculation assumes

This line includes an intercept and minimizes vertical errors in Y. Fitting through the origin or treating measurement error in both axes produces a different problem. A good-looking line does not establish causality, validate a linear model or supply uncertainty. Inspect curvature and unusual points before treating coefficients as a useful description.

Do not extend the claim beyond the data

The maker draws its fitted line between the smallest and largest observed X values. Extrapolation would require an additional assumption about the relationship outside that range. If all X values are identical, the denominator is zero and the slope is undefined; the editor reports that instead of fabricating a line.

A related chart you can inspect

Positive correlation scatter plot with a fitted line
Positive correlation scatter plot with a fitted line. Original fictional data; this linked example has its own complete input and calculation settings.

Open the worked example ↗

References and reproducibility

The worked arithmetic and teaching examples on this page are original. Background reading: NIST scatter plot background. Source code and reuse terms expose the implemented calculations.

Written by SupaMakers for ChartsAI · September 8, 2026.

Continue with a related question