About this example
R’s datasets::cars records the speed and stopping distance of 50 cars measured in the 1920s (Ezekiel 1930). The points rise steadily with speed, and the spread widens at higher speeds, which is visible because every car is drawn.
The line is the ordinary least-squares fit: distance = −17.58 + 3.93 × speed, so each extra mph adds about 3.9 ft (95% CI 3.10 to 4.77). Pearson’s r is 0.807 (95% CI 0.682 to 0.886, p < 0.001). These match R’s lm, confint and cor.test, and the downloadable R script reproduces them.
The shaded band is the 95% confidence band for the mean distance at each speed, not the range where individual cars fall; it is narrowest near the mean speed. A negative intercept shows that a straight line is only an approximation near zero speed, so the line is not extended beyond the observed 4–25 mph.
Sources: R datasets::cars — Ezekiel (1930)
The data
| X | Y |
|---|---|
| 4 | 2 |
| 4 | 10 |
| 7 | 4 |
| 7 | 22 |
| 8 | 16 |
| 9 | 10 |
| 10 | 18 |
| 10 | 26 |
| 10 | 34 |
| 11 | 17 |
| 11 | 28 |
| 12 | 14 |
| 12 | 20 |
| 12 | 24 |
| 12 | 28 |
…and 35 more rows. Open the example to see all of them.
Source: R datasets::cars (Ezekiel 1930). The line is an ordinary least-squares fit with its 95% confidence band; r and its CI match R cor.test. Open the example, replace the data with your own, and export the figure as SVG, PDF, PNG or TIFF.