---
title: "Statistics for measurements: confidence and error bars"
heading: How sure are you of a measured number?
eyebrow: A11 · Lesson 36 · Confidence and error bars
xp: 40
---

::: hook
You measure a reference voltage ten times and get readings that scatter around 5.002 V. What should you write down? "5.002 V" claims too much; "about 5 V" throws away information. The honest answer is a value with an uncertainty, like 5.002 ± 0.003 V, where the ± has a precise meaning. Getting that number right, and combining uncertainties when measured values go into a calculation, is everyday engineering.

::: play
- Each press of New samples takes $n$ readings of a true 5 V reference, each with random noise σ = 20 mV. The readouts give their mean, their standard deviation, and a 95% confidence interval for the true value.
- Press New samples a dozen times. How often does the interval miss 5 V?
- Raise $n$. What happens to the interval's width? To the standard deviation of the readings themselves?
:::
:::

```sim plot
view: random
x: v = 4.9..5.1 V
slider: n = 3..400 = 10 log
sample: 5 + 0.02*randn(1) | mean: M | sd: S
trials: n
bins: 40
marker: x = 5 | label: true value
readout: mean = M V | digits: 5
readout: sd of readings = 1000*S mV
readout: 95% interval ± = 1000*1.96*S/sqrt(n) mV
readout: covers 5 V? (1 for yes) = step(1.96*S/sqrt(n) - abs(M - 5))
```

```sim plot
view: random
x: v = 4.95..5.05 V
slider: n = 4..100 step 4 = 16
sample: 5 + 0.02*randn(n)
trials: 20000
bins: 60
marker: x = 5 - 1.96*0.02/sqrt(n) | label: −1.96σ/√n
marker: x = 5 + 1.96*0.02/sqrt(n) | label: +1.96σ/√n
measure: step(1.96*0.02/sqrt(n) - abs(v - 5)) | name: C
readout: experiments whose interval covers 5 V = 100*C %
```

::: predict
## You report a 95% confidence interval from your ten readings. What does "95%" mean?

- [ ] 95% of your readings lie inside it
- [x] If you repeated the whole experiment many times, about 95% of the intervals you'd compute would contain the true value
- [ ] There's a 95% chance the next reading lands inside it
- [ ] The measurement is 95% accurate

::: reveal
It's a statement about the method. Each experiment gives a slightly different interval; 95% of them catch the true value and 5% miss. The second sim repeats the experiment 20,000 times and counts. The interval is much narrower than the scatter of individual readings, since it describes the mean, which is $\sqrt n$ times steadier.
:::
:::

::: nameit
## Reporting a measurement

From $n$ readings $x_1, \ldots, x_n$:

- the **sample mean** $\bar x = \frac1n\sum x_i$, the best estimate of the true value;
- the **sample standard deviation** $s = \sqrt{\frac{1}{n - 1}\sum(x_i - \bar x)^2}$, how much individual readings scatter. (Dividing by $n - 1$ instead of $n$ corrects for measuring the spread around $\bar x$, which sits closer to the data than the true mean does.);
- the **standard error** $s/\sqrt n$, how much the mean itself would scatter from one experiment to the next (lesson 33's averaging rule).

**Confidence interval.** For many readings with Gaussian noise, the true value lies within

$$\bar x \pm 1.96\,\frac{s}{\sqrt n}$$

with 95% confidence. With only a few readings, $s$ is itself uncertain, and the 1.96 is replaced by a larger factor from Student's t distribution: 2.26 for 10 readings, 2.78 for 5, 12.7 for 2.

**Error bars** on a graph must say what they show: ±1 standard deviation (the spread of readings), ±1 standard error, or a 95% interval. They differ by large factors, so an error bar with no label means very little.

**Combining uncertainties.** If a result $f$ is calculated from independent measured quantities, small errors propagate through the partial derivatives (A9.6) and add like independent noise (lesson 9):

$$\sigma_f^2 = \left(\frac{\partial f}{\partial x}\right)^2\sigma_x^2 + \left(\frac{\partial f}{\partial y}\right)^2\sigma_y^2$$

For products and quotients this becomes a rule for *relative* uncertainties: for $P = VI$ or $R = V/I$, $\left(\frac{\sigma_P}{P}\right)^2 = \left(\frac{\sigma_V}{V}\right)^2 + \left(\frac{\sigma_I}{I}\right)^2$.

**How to write it.** Round the uncertainty to one or two significant figures, and round the value to the same decimal place: 5.0021 V with an uncertainty of 0.0034 V is written 5.002 ± 0.003 V. And keep in mind that all of this covers only random error. A systematic error, like a miscalibrated meter, shifts every reading and has to be estimated separately.
:::

::: example
## 25 readings average 5.012 V with a sample standard deviation of 10 mV. Report the result with a 95% interval.

::: solution
1. **Standard error.**
   $$\frac{10\ \text{mV}}{\sqrt{25}} = 2\ \text{mV}$$
2. **95% half-width.**
   $$1.96 \times 2 = 3.9\ \text{mV}$$

**Answer:** report $5.012 \pm 0.004$ V (95%).
:::
:::

::: example
## Power is computed as $P = V^2/R$ with $V = 5.00 \pm 0.02$ V and $R = 100 \pm 1$ Ω, independent. What is $P$ with its uncertainty?

::: solution
1. **Relative errors.** 0.4% in $V$, which counts twice because it's squared, and 1% in $R$.
2. **Combine them.**
   $$\sqrt{0.8^2 + 1^2} = 1.28\%$$
3. **The power.** $P = 0.250$ W, and 1.28% of that is 0.003 W.

**Answer:** $P = 0.250 \pm 0.003$ W.
:::
:::

::: example
## A current is computed as $I = V/R$, with $V$ known to 1% and $R$ to 0.5%, independently. How uncertain is $I$?

::: solution
1. **Add in squares.** For products and quotients, relative uncertainties add in squares:
   $$\sqrt{1^2 + 0.5^2} = 1.12\%$$
2. **The larger term dominates.** The larger term dominates again: improving the resistor to 0.1% would only bring it to 1.005%.

**Answer:** $I$ is uncertain by 1.12%.
:::
:::

::: check
given: s = 2 | 5 | 10 | 20; n = 4 | 16 | 25 | 100
answer: s/sqrt(n)
unit: mV
tolerance: 0.5%

## Readings scatter with a standard deviation of {s} mV. What is the standard error of the mean of {n} of them?

::: right
Right. $s/\sqrt n$ = {answer}.
:::

::: misses
- [s] That's the scatter of single readings. The mean is steadier.
- [s/n] Divide by $\sqrt n$, not n.
- [any] Not yet. Standard error $= s/\sqrt n$.
:::
:::

::: check
given: s = 4 | 10 | 20; n = 25 | 64 | 100
answer: 1.96*s/sqrt(n)
unit: mV
tolerance: 1%

## From {n} readings with standard deviation {s} mV, what is the half-width of the 95% confidence interval for the mean?

::: right
Right. $1.96\,s/\sqrt n$ = {answer}.
:::

::: misses
- [1.96*s] That's where 95% of single readings fall. The mean is known $\sqrt n$ times better.
- [s/sqrt(n)] That's one standard error, about a 68% interval. For 95%, multiply by 1.96.
- [any] Not yet. $1.96 \times$ the standard error.
:::
:::

::: check
kind: parts
given: a = 4 | 6; b = 7 | 9; c = 11 | 14

## Three readings: {a}, {b} and {c} mV.

::: part
answer: (a + b + c)/3
unit: mV
tolerance: 0.5%

### What is their mean?

::: misses
- [any] Add them and divide by 3.
:::
:::

::: part
answer: sqrt(((a - (a + b + c)/3)^2 + (b - (a + b + c)/3)^2 + (c - (a + b + c)/3)^2)/2)
unit: mV
tolerance: 0.5%

### What is their sample standard deviation?

::: misses
- [sqrt(((a - (a + b + c)/3)^2 + (b - (a + b + c)/3)^2 + (c - (a + b + c)/3)^2)/3)] Divide by $n - 1 = 2$, not 3.
- [((a - (a + b + c)/3)^2 + (b - (a + b + c)/3)^2 + (c - (a + b + c)/3)^2)/2] That's the variance. Take the square root.
- [any] Square each distance from the mean, add, divide by $n - 1$, take the root.
:::
:::

::: right
Right. With so few readings, the 95% interval should use Student's factor 4.30 instead of 1.96.
:::
:::

::: check
given: rv = 1 | 2 | 3; ri = 2 | 4
answer: sqrt(rv^2 + ri^2)
unit: %
tolerance: 0.5%

## A power is calculated as $P = VI$. V is known to {rv}% and I to {ri}%, independently. How well is P known?

::: right
Right. For a product the relative uncertainties add in quadrature: $\sqrt{\given{rv}^2 + \given{ri}^2}$ = {answer}.
:::

::: misses
- [rv + ri] That's the worst case. Independent errors add in quadrature.
- [rv*ri] Combine the relative errors as $\sqrt{a^2 + b^2}$.
- [any] Not yet. $\sigma_P/P = \sqrt{(\sigma_V/V)^2 + (\sigma_I/I)^2}$.
:::
:::

::: check
given: s = 10 | 20 | 50; w = 1 | 2 | 5
answer: (1.96*s/w)^2
tolerance: 1%

## Readings scatter with σ = {s} mV. About how many must you average for a 95% interval of ±{w} mV?

::: right
Right. Solve $1.96\,s/\sqrt n = w$: $n = (1.96\,s/w)^2$ ≈ {answer}.
:::

::: misses
- [1.96*s/w] Square it: the interval shrinks as $1/\sqrt n$.
- [(s/w)^2] Include the 1.96 for 95%.
- [any] Not yet. Solve $1.96\,s/\sqrt n = w$ for n.
:::
:::

::: check
kind: parts
given: a = 0.5 | 1; b = 0.2 | 2

## $I = V/R$ with $V$ uncertain by {a}% and $R$ by {b}%, independently.

::: part
answer: sqrt(a^2 + b^2)
unit: %
tolerance: 0.5%

### What is the relative uncertainty of $I$?

::: misses
- [a + b] That's the worst case; independent uncertainties add in squares.
- [any] $\sqrt{a^2 + b^2}$.
:::
:::
:::

::: check
kind: derivation
vars: a = 0.1..2, b = 0.1..2

## $P = V^2/R$ with relative uncertainties $a$ in $V$ and $b$ in $R$ (percent).

::: step
answer: sqrt((2*a)^2 + b^2)

### What is the relative uncertainty of $P$?
:::

::: right
Right. The square doubles $V$'s contribution.
:::
:::

::: explain
## Why is the uncertainty of an averaged measurement smaller than the scatter of the individual readings, and why doesn't averaging fix everything?

::: model
Each reading has a random error, and those errors partly cancel when you average them, so the mean scatters from experiment to experiment by only $s/\sqrt n$, much less than single readings do. That's what the confidence interval describes. But averaging only cancels errors that change from reading to reading. A systematic error, like an offset in the meter or a wrong calibration, is the same in every reading, so it survives the average untouched and has to be found and corrected by other means.
:::
:::

::: practice

::: check
given: s = 3 | 6 | 9; n = 9 | 36
answer: s/sqrt(n)
unit: mV
tolerance: 0.5%

## σ = {s} mV, n = {n}. What is the standard error?

::: misses
- [s/n] Divide by $\sqrt n$.
- [any] $s/\sqrt n$.
:::
:::

::: check
given: rv = 1 | 3; rr = 2 | 4
answer: sqrt(rv^2 + rr^2)
unit: %
tolerance: 0.5%

## A current is found as $I = V/R$, with V known to {rv}% and R to {rr}%. How well is I known?

::: misses
- [rv + rr] Independent errors add in quadrature.
- [abs(rv - rr)] Dividing doesn't subtract uncertainties: they still add in quadrature.
- [any] $\sqrt{a^2 + b^2}$ for products and quotients.
:::
:::

::: check
given: m = 1..9 int; se = 0.1 | 0.2 | 0.5
answer: m + 1.96*se
tolerance: 0.5%

## A mean is {m} V with a standard error of {se} V. What is the upper end of the 95% interval?

::: misses
- [m + se] That's a 68% interval. Use 1.96 standard errors.
- [any] $\bar x + 1.96\,\text{SE}$.
:::
:::
:::
