Skip to content
Leantensify Learn

How does one measurement move with another — and is a straight line the right shape?

Fit a line to two measurements — with the residual plot beside it, never behind a toggle, because the fit succeeds whether or not a straight line was ever the right shape.

Regression & Correlation · analyze · Green Belt

Use this when

  • You suspect a process input drives an output and want to know how much
  • Somebody has quoted an R-squared and you want to know what the data actually looks like
  • You need to predict a value at a setting you have measured around

Regression & Correlation

sandbox

picking time = 3.2597 + 0.4297 x lines on the order

Over the range in this data, picking time rises by about 0.4297 for each one-unit increase in lines on the order (p < 0.001), and the data is consistent with a slope anywhere from 0.3918 to 0.4676. The line accounts for 96.9% of the variation in picking time, and typical points miss it by about 0.7424 in the units of picking time. A fitted line describes how these two columns moved together in this data. It is not evidence that one causes the other: the same line appears when the causation runs the other way, and when something not in the data drives both. Deciding causation needs an argument regression cannot supply — usually a change made deliberately, with everything else held still.

Slope

0.4297

0.9692

Adjusted R²

0.9675

r

0.9845

Slope SE
0.0180
t
23.818 on 18 df
p
p < 0.001
95% interval on the slope
0.3918 to 0.4676
Correlation interval
0.960 to 0.994
Residual std error
0.7424
Scatter plot of 20 points, picking time against lines on the order, with the fitted line picking time = 3.2597 + 0.4297 x lines on the order. The line accounts for 96.9% of the variation in picking time. No point was flagged as unusually influential or far out in x.19.814.09339lines on the orderpicking time
Residual plot: the vertical distance of each point from the fitted line, against the fitted value. A straight-line relationship shows no pattern here. No curvature was detected by the quadratic term test. Residuals run from -1.616 to 1.078, with a typical size of 0.742.on the line+1.6161.616Fitted picking timeResidual
Left: the data and the fitted line, drawn only across the range that was measured. Right: the same points with the line subtracted — a straight-line relationship leaves no pattern here. Squares mark points far out in lines on the order; diamonds mark points that move the line substantially if removed.
Show the data behind these charts
Scatter plot of 20 points, picking time against lines on the order, with the fitted line picking time = 3.2597 + 0.4297 x lines on the order. The line accounts for 96.9% of the variation in picking time. No point was flagged as unusually influential or far out in x. Residual plot: the vertical distance of each point from the fitted line, against the fitted value. A straight-line relationship shows no pattern here. No curvature was detected by the quadratic term test. Residuals run from -1.616 to 1.078, with a typical size of 0.742.
Rowlines on the orderpicking timeFittedResidualLeverageCook’s D
165.45.838-0.4380.1860.049
297.77.1270.5730.1380.055
3118.57.9870.5130.1110.034
4149.49.2760.1240.0810.001
5179.910.565-0.6650.0600.027
61912.411.4250.9750.0530.051
72212.412.714-0.3140.0500.005
82412.913.573-0.6730.0550.025
92714.614.862-0.2620.0700.005
102916.815.7221.0780.0860.108
113116.916.5810.3190.1070.012
123418.517.8710.6290.1470.072
1376.76.2680.4320.1690.041
14126.88.416-1.6160.1000.293
15161010.135-0.1350.0660.001
162112.912.2840.6160.0500.019
172614.514.4330.0670.0640.000
183016.816.1520.6480.0960.045
193316.717.441-0.7410.1320.087
203617.618.73-1.130.1790.309

Checks on the fit

  • ClearIs a straight line the right shape?No curvature detected (quadratic term p = 0.608). Still look at the residual panel: this tests for a bend, not for every shape.
  • ClearDo the residuals change sign as often as chance would?13 runs from 11 above and 9 below the line (p = 0.454). Consistent with chance — but this test is underpowered at these sample sizes and misses curvature that is plain on the plot, so it clears far more than it should.
  • ClearIs any point far out in lines on the order?No point exceeds a leverage of 0.200, so no single lines on the order value dominates the fit.
  • ClearWould removing one row change the answer?No row has a Cook’s distance above 1. The conclusion does not rest on any single observation.

A fitted line describes how these two columns moved together in this data. It is not evidence that one causes the other: the same line appears when the causation runs the other way, and when something not in the data drives both. Deciding causation needs an argument regression cannot supply — usually a change made deliberately, with everything else held still.

lines on the order first, then picking time. Commas or tabs; a header row is detected.

Load Anscombe’s quartet

Four datasets with the same slope, intercept, R² and correlation. Load each in turn and watch the residual panel — it is the only thing that changes.

How this is calculated
  • The line is ordinary least squares: slope = Sxy/Sxx, intercept = ȳ − slope·x̄. Inference on the slope uses t = slope/SE on n − 2 degrees of freedom.
  • Leverage hi = 1/n + (xi − x̄)²/Sxx, flagged above 2p/n. The leverages always sum to 2, the number of parameters.
  • Cook’s distance measures how far the fitted line moves when a point is deleted, flagged above 1. Where leverage is exactly 1 it is reported as undefined rather than as zero — the point is fitted perfectly because it alone determines that part of the line, which is total influence, not none.
  • Curvature is tested by adding a quadratic term and testing its coefficient. A runs test on the residual signs is weaker: on Anscombe’s second set, an exact parabola, it gives p = 0.067 and would be waved through, while the quadratic term gives p below 10⁻¹⁵.
  • The correlation interval uses Fisher’s z-transformation, so it cannot run past ±1 the way a symmetric interval on r does.
  • Below 6 pairs the tool refuses. R² is close to 1 by construction at that size and the residuals cannot show whether a straight line was ever the right shape.

Source: Anscombe, F.J. (1973), ‘Graphs in Statistical Analysis’, The American Statistician 27(1), 17–21; Montgomery, D.C., Peck, E.A. and Vining, G.G., Introduction to Linear Regression Analysis 5e, Ch. 2 and Ch. 4; Cook, R.D. (1977), Technometrics 19(1), 15–18.

How this is calculated

Ordinary least squares: slope = Sxy/Sxx, intercept = ybar - slope*xbar. Inference on each coefficient by t = estimate/SE on n-2 degrees of freedom, with confidence intervals from the exact t distribution. R-squared is reported alongside adjusted R-squared. The correlation interval uses Fisher's z-transformation so it cannot run past +/-1. Three diagnostics run automatically: leverage h = 1/n + (x-xbar)^2/Sxx flagged above 2p/n; Cook's distance flagged above 1, and reported as undefined rather than zero where leverage is exactly 1; and curvature tested by adding a quadratic term, fitted on the part of x-squared orthogonal to x so the coefficient and its t match the full three-parameter fit. A runs test on residual signs is also reported and labelled underpowered, because on an exact parabola of eleven points it returns p = 0.067. Prediction gives both a prediction interval for a single new observation and the narrower interval for the mean response, and flags any x outside the fitted range as extrapolation.

Source: Anscombe, F.J. (1973), 'Graphs in Statistical Analysis', The American Statistician 27(1), 17-21; Montgomery, D.C., Peck, E.A. and Vining, G.G., Introduction to Linear Regression Analysis 5e, Ch. 2 and Ch. 4; Cook, R.D. (1977), Technometrics 19(1), 15-18.

Learn the method