← Math
Math

Error bars and uncertainty communication

Zero failures in 300 sessions: is the canary safe?

Make a rate’s uncertainty and the policy using it agree.

Outcome

Say what an error bar encodes, compute a Wilson interval with a positive upper endpoint at zero events, keep the caption and critical value together, and decide on the upper end.

Terminology (6)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Error bar
A drawn range around an estimate. It is meaningless until the caption says what it encodes: SD, SE or a confidence interval, and at what level.
Wald interval
Rate ± z standard errors. Simple, but it collapses to zero width when no events were seen.
Wilson score interval
An interval for a proportion that stays inside 0..1 and keeps a positive upper end for zero events.
Critical value Also z
Rounded normal multipliers for two-sided intervals: 1.645 for 90%, 1.96 for 95%, 2.576 for 99%.
Upper bound policy
A decision rule using the interval’s upper endpoint under a declared method and confidence level.
Rule of three
With zero events in n independent constant-risk trials, about 3/n is an approximate 95% one-sided upper confidence bound.

Why this matters

Canary results, error rates, conversion rates and survey answers are proportions from a limited number of trials. A point estimate without a range invites decisions the data cannot support, and a range drawn without a caption or with the wrong formula is worse: it looks precise. Rollout policies are safer when they are written on the end of the range that matters.

This lesson assumes standard errors and confidence bands from the previous lesson.

What an error bar claims

An error bar is a visual range whose meaning comes from its method and caption. Standard deviation describes spread, standard error describes uncertainty in an estimate, and a confidence interval comes from an interval procedure with a nominal coverage level under stated assumptions. One-sided and two-sided intervals make different claims.

This lesson studies a proportion: failed sessions divided by all sessions. Its Wilson interval assumes independent trials with a common failure probability over the window. The observed fraction, interval endpoints and rollout limit are distinct quantities. Keep the method, confidence level and sidedness attached to the computed interval before using an endpoint in a decision.

01What the bar encodes

What the bar encodes

The canary dashboard draws the failure rate as 0% with no error bar at all, because the bar’s formula gives zero width when nothing failed. The 95% two-sided Wilson upper endpoint is about 1.26%, so this rollout policy still cannot approve a 1% limit.

The team first reproduces the dashboard’s existing Wald bar before replacing it. A bar may encode SD, SE or a confidence interval. Under a symmetric normal approximation, those conventions introduce factors of √n and z; Wilson intervals need not be symmetric around the observed rate. Read the caption, then predict the three lines this program prints.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const wilson = (k: number, n: number, z: number) => {
  if (k === 0) return `0.0000 ${((z * z) / (n + z * z)).toFixed(4)}`;
  if (k === n) return `${(n / (n + z * z)).toFixed(4)} 1.0000`;

  const p = k / n;
  const scale = 1 + (z * z) / n;
  const centre = (p + (z * z) / (2 * n)) / scale;
  const half = (z / scale) * Math.sqrt((p * (1 - p)) / n + (z * z) / (4 * n * n));

  return `${Math.max(0, centre - half).toFixed(4)} ${(centre + half).toFixed(4)}`;
};

const p = 0 / 300; // no failed sessions out of 300

console.log(
  `${p.toFixed(4)} ${(p + 1.96 * Math.sqrt((p * (1 - p)) / 300)).toFixed(4)}`
); // Wald
console.log(wilson(0, 300, 1.96)); // Wilson, 95%
console.log(wilson(6, 400, 2.576)); // 6 of 400, Wilson, 99%
Why is the first line 0.0000 0.0000?

failed / sessions divides as floating point. With zero sessions it is NaN, so check sessions first and return null.

02Wilson and zero events

Wilson and zero events

Treat each session as one pass/fail trial, independent with a common failure probability over the window. Let k be failed sessions, n all sessions and p̂=k/n the observed rate. Wilson inverts the score-test inequality (p̂−p)² ≤ z²p(1−p)/n for the hypothesized rate p. Using the candidate p in the variance keeps positive risks in consideration even when the observed rate is 0.

Its endpoints can be calculated as centre ± half, where scale = 1+z²/n, centre = (p̂+z²/(2n))/scale, and half = (z/scale)√(p̂(1−p̂)/n+z²/(4n²)). This shifts the centre toward 1/2; z²/(2n) is a numerator correction, not the final shift itself.

For zero events the endpoints simplify to 0 and z²/(n+z²); for all failures they are n/(n+z²) and 1. Use these count-boundary forms directly so cancellation cannot turn an exact zero endpoint into a tiny positive number. At n = 300, z = 1.96, the upper endpoint is 3.8416/303.8416 ≈ 0.01264, or 1.26%. The nominal confidence describes the interval procedure under the model, not a guarantee that the true risk is inside this particular interval. Correlated sessions or selection into the canary need separate analysis. See the NIST Wilson formula and sidedness discussion.

Failure-rate intervals at 95%
Failed / sessionsWaldWilson
0 / 3000.00% to 0.00%0.00% to 1.26%
6 / 4000.31% to 2.69%0.69% to 3.23%

03Caption and critical value

Caption and critical value

The published constants here are rounded normal critical values for two-sided intervals. A 99% interval uses z = 2.576. The same 6 failures in 400 sessions give 0.55% to 4.03%, wider than the 95% interval. A chart captioned 99% but computed with 1.96 claims more confidence than its bars hold. Keep the caption and the critical value in the same place in code, so changing one changes both.

04Policy on the upper end

Policy on the upper end

The policy is ship if the computed upper endpoint is ≤ 3%, hold if the lower is > 3%, and more-data otherwise. With 6 of 400 sessions failed, the 95% two-sided Wilson interval is 0.69% to 3.23%. What is the verdict?

05Bars the counts cannot support

Bars the counts cannot support

06Gate the canary rollout

Gate the canary rollout

Repair the existing dashboard’s rate uncertainty, replace its zero-width rare-event bar with Wilson, then make the rollout decision use the same confidence as its caption. Use computed binary64 endpoints before four-decimal display rounding: ship when upper ≤ parsed limit, hold when lower > limit, otherwise more-data. There is no extra epsilon. Known count endpoints use the analytic branches above; interior values use the displayed scale/centre/half evaluation order. Last-bit native arithmetic differences are not a statistical-confidence statement.

In the frontend A self-describing tooltip in Next.js and Svelte Optional

The tooltip derives the critical value and interval from the same confidence input, then displays that method, sidedness, counts and confidence together. It accepts valid counts with 0 ≤ failed ≤ sessions and shows “no sessions yet” for a zero denominator. A separate precomputed interval prop could silently retain a 95% interval under a 99% caption, so the derivation belongs with the metadata it displays.

Estimate.tsx
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
type Confidence = 90 | 95 | 99;

function describe(failed: number, sessions: number, confidence: Confidence) {
  if (sessions === 0) return null;

  const z = { 90: 1.645, 95: 1.96, 99: 2.576 }[confidence];
  const metadata = { failed, sessions, confidence, z };

  if (failed === 0) {
    return { ...metadata, low: 0, high: (z * z) / (sessions + z * z) };
  }

  if (failed === sessions) {
    return { ...metadata, low: sessions / (sessions + z * z), high: 1 };
  }

  const rate = failed / sessions;
  const scale = 1 + (z * z) / sessions;
  const centre = (rate + (z * z) / (2 * sessions)) / scale;
  const half =
    (z / scale) *
    Math.sqrt((rate * (1 - rate)) / sessions + (z * z) / (4 * sessions * sessions));

  return {
    ...metadata,
    low: Math.max(0, centre - half),
    high: Math.min(1, centre + half)
  };
}

export function FailureRateTooltip({
  failed,
  sessions,
  confidence
}: {
  failed: number;
  sessions: number;
  confidence: Confidence;
}) {
  const report = describe(failed, sessions, confidence);

  if (report === null) return <span>No sessions yet</span>;

  return (
    <span>
      {report.failed} of {report.sessions} failed: {(report.low * 100).toFixed(2)}% to{' '}
      {(report.high * 100).toFixed(2)}% ({report.confidence}% two-sided Wilson, z ={' '}
      {report.z})
    </span>
  );
}

Check this idea later
Under a normal approximation, a chart’s bars are labelled “±1 SE”. About what confidence do they show?
With independent constant-risk sessions and zero failures in 3,000 sessions, what approximate 95% one-sided upper bound does the rule of three give?
Sources

Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The canary is a worked model.

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.