Fitted line plot: simple linear regression with an example

Updated

A fitted line plot draws your data as a scatterplot with the least-squares regression line through it, and prints the equation, S and R² beside it. It is simple linear regression as a picture: one predictor, one response, and a line (or a curve, if you choose a quadratic or cubic model) that you can check by eye against the points.

When to use it

  • You want to know how one variable changes with another: clamp force with torque, hardness with tempering temperature, drift with time.
  • You need a calibration or conversion equation from one predictor.
  • You want to see whether a straight line is good enough, or whether the data bend.
  • You want prediction bands to show how far individual values scatter around the line.

With two or more predictors, use regression analysis. When both variables carry measurement error, as when you compare two gages, use orthogonal regression. For a curve with a known physical form, such as exponential decay, see nonlinear regression.

How it works

Least squares picks the slope and intercept that make the sum of squared vertical distances from the points to the line as small as possible:

b₁ = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)² b₀ = ȳ − b₁x̄

The plot reports:

  • The equation ŷ = b₀ + b₁x.
  • S, the standard deviation of the points around the line: √(SSE / (n − 2)).
  • R², the share of the variation in y explained by the line, and R²(adj).
  • An ANOVA table whose F test asks whether the slope differs from zero.

A good plot also draws two pairs of bands. The confidence band shows where the true mean line probably lies; the prediction band shows where a single new observation will probably fall. At a value x₀, with Sxx = Σ(xᵢ − x̄)² and t the 97.5th percentile of the t distribution with n − 2 degrees of freedom:

95% PI = ŷ₀ ± t · S · √(1 + 1/n + (x₀ − x̄)²/Sxx)

The confidence interval has the same form without the "1 +" under the root, so it is always narrower.

A quadratic model adds an x² term (ŷ = b₀ + b₁x + b₂x²). Choose it when the residuals bend and when its x² term is significant, not just because R² rises: R² always rises when you add a term.

Example

An assembly line tightens M10 bolts by torque, but the design calls for clamp force. A technician tightens 16 bolts on a load cell, two at each torque from 20 to 55 N·m, and records the clamp force (kN):

Torque (N·m)2020252530303535
Clamp force (kN)9.69.012.212.615.615.217.016.6
Torque (N·m)4040454550505555
Clamp force (kN)20.921.922.321.023.526.927.425.1
Clamp force versus tightening torque, with fitted line10152025Clamp force (kN)20304050Torque (N·m)
Clamp force versus tightening torque, with fitted line

The fitted line:

Clamp force = 0.157 + 0.4905 · Torque

S = 1.202 kN, R² = 96.15%, R²(adj) = 95.87%.

SourceDFSSMSFP
Regression1505.19505.19349.62< 0.001
Error1420.231.445
Total15525.42

The slope's standard error is 0.0262 (t = 18.70), and the intercept, 0.157 with a standard error of 1.029, is not distinguishable from zero (p = 0.881), as physics expects: no torque, no clamp force.

At the specified torque of 40 N·m the line predicts 19.78 kN. The 95% confidence interval for the mean clamp force is 19.12 to 20.44 kN, but the 95% prediction interval for a single bolt is 17.11 to 22.44 kN, with t = 2.145 for 14 degrees of freedom.

A quadratic model gives a Torque² coefficient of −0.00374 with p = 0.161 and lowers S only to 1.153 kN, so the straight line is enough.

How to read the results

  • The slope is the answer to most questions. Each extra N·m adds about 0.49 kN of clamp force.
  • S and the prediction band tell you what to expect for one part. At 40 N·m, single bolts range over about ±2.7 kN, roughly ±13% of the mean. That scatter comes from friction, and no torque setting removes it.
  • Look at the residuals, not only the line. Here the scatter grows with torque: the residuals have a root mean square of about 0.55 kN from 20 to 35 N·m and about 1.49 kN from 40 to 55 N·m. The prediction band assumes constant spread, so it is too wide at low torque and too narrow at high torque. Bolt friction scatters in proportion to the load, which explains the funnel.
  • R² depends on the range of x. Testing only from 38 to 42 N·m would give the same scatter but a far lower R². Judge the fit by S, not R².
  • A significant slope is not a strong relation. With many points, even a weak slope gets a tiny p-value. Read the size of the slope and S.

Common mistakes

  • Using the confidence band as if it held individual parts. It describes the mean line. For a part against a limit, use the prediction band.
  • Adding a quadratic term because R² rose. Check that its p-value is small and that the residuals of the straight line actually bend.
  • Swapping x and y. Regressing torque on clamp force gives a different line. Put the variable you set or know on x and the one you predict on y.
  • Extrapolating past the data. Above 55 N·m the bolt may yield and the line stops applying.
  • Fitting a line to two clouds. If the points form two clusters, the line merely connects them; investigate the clusters instead.

Frequently asked questions

What is the difference between a fitted line plot and a scatterplot?

A scatterplot only shows the points. A fitted line plot adds the regression line, its equation, S, R² and, optionally, confidence and prediction bands.

For a straight line with one predictor, R² is the square of Pearson's correlation r. Here r = 0.981 and R² = 0.9615.

Should I force the line through zero?

Usually not, even when physics says it should pass through the origin. Fit the intercept and check whether it differs from zero, as in the example. Forcing it changes the meaning of R² and can bias the slope if the relation bends near zero.

When should I use a quadratic or cubic model?

When the residuals of the straight line show a curve and the higher-order term is significant. Keep cubic models for cases with a clear reason; they bend wildly outside the data.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab