plplot.org

Plate 01 · Error bars

Error bars: SD, SE or confidence interval, and what overlap does and does not tell you

By plplot.org ·

An error bar is a line through a data point that shows uncertainty or spread. The same drawing can mean three different things, and a reader cannot tell which unless you say so. That is the first rule of the most-cited guide on the subject, Cumming, Fidler and Vaux (2007): state in the legend what the bars are, and state n.

The three kinds of error bar

Cumming and colleagues split error bars into two families.

  • Standard deviation (SD) is descriptive: it shows how spread out the data are. About two thirds of values fall within one SD of the mean. More data does not make SD smaller.
  • Standard error (SE), SD divided by the square root of n, is inferential: it shows how much the mean itself would vary if you repeated the study. It shrinks as n grows.
  • 95% confidence interval (CI) is also inferential: a range that, across repeated studies, would contain the true mean 95% of the time. For n of 10 or more it is roughly the mean plus or minus two SE; for n = 3 it is about four SE wide on each side, because few data points make the estimate uncertain.

Use SD when the point is the variability of the measurements. Use SE or CI when you compare means, for example a treatment with its control.

Reading gaps and overlap

Less overlap between two error bars means a smaller P value, but the exact rule depends on the kind of bar and on n. For two independent groups, Cumming and colleagues give these rules of thumb:

Bars n Roughly P = 0.05 when Roughly P = 0.01 when
95% CI 10 or more the bars overlap by half an arm the tips just touch
95% CI 3 the bars overlap by one full arm they overlap by half an arm
SE 10 or more there is a gap of one SE between them the gap is two SE

An arm is the length of the bar from the mean to one end, averaged over the two groups. The rules do not apply to repeated measurements of the same group: there the bars say nothing about the difference, and you need a paired analysis or a plot of the differences with their own CI.

These rules are worth learning because many researchers get them wrong. In a test with 473 authors of published papers, Belia et al. (2005) found severe misconceptions about how error bars relate to significance: respondents did not separate CI from SE bars, and ignored whether the means came from independent groups.

Common mistakes

Error bars from replicates. n counts independent experiments, not repeated measurements of the same sample. Triplicate wells repeated in four independent experiments give n = 4, not 12. Bars from replicate wells show pipetting accuracy, not reproducibility, and Cumming and colleagues say they should not be shown at all. Suspiciously small bars are often a sign of this.

Bars on a “representative experiment”. One experiment is n = 1. It should carry no error bars or P values.

Bars when n is tiny. With n = 3, plot the individual points, with or without a bar. Three dots tell the reader more than a bar computed from three values.

Unlabelled bars. A bar with no legend could be SD, SE or CI, and they can differ several-fold: SE is SD divided by the square root of n, and a 95% CI is two to four SE on each side. Always say which, and give n.

Making it

Every plotting library draws error bars from an array of values, one per point. In matplotlib, errorbar takes yerr for symmetric bars, or a pair of arrays for asymmetric ones:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2.1, 3.9, 6.2, 7.8, 10.1]
err = [0.3, 0.4, 0.5, 0.4, 0.6]

fig, ax = plt.subplots(figsize=(4, 3))
ax.errorbar(x, y, yerr=err, fmt="o", capsize=3)
ax.set_xlabel("Dose (mg)")
ax.set_ylabel("Response")
fig.tight_layout()
fig.savefig("errorbars-matplotlib.png", dpi=150)

The plotting call does not know whether err holds SD, SE or a CI half-width. You compute it, and you say which one it is in the caption. The same figure in Plotly, gnuplot, ggplot2 and PLplot is below; their full code is in Plot Rosetta.

Sources

  1. Error bars in experimental biologyCumming, Fidler and Vaux, Journal of Cell Biology 177(1), 2007
  2. Researchers misunderstand confidence intervals and standard error barsBelia, Fidler, Williams and Cumming, Psychological Methods 10(4), 2005
  3. matplotlib.pyplot.errorbarMatplotlib documentation