theme = Generators.observe(notify => {const read = () => {const css =getComputedStyle(document.body);const v = (name, fallback) => (css.getPropertyValue(name).trim() || fallback);return {dark:document.body.classList.contains("quarto-dark"),fg:v("--bs-body-color","#212529"),bg:v("--bs-body-bg","#ffffff"),muted:v("--bs-secondary-color","#6c757d"),grid:v("--bs-border-color","#dee2e6"),primary:v("--bs-link-color","#0d6efd"),accent:v("--bs-danger","#dc3545"),good:v("--bs-success","#198754") }; };// Quarto swaps stylesheets when the theme changes, and the new variables apply only once// the stylesheet has loaded; read them again shortly after, and keep the last reading.let last ="";const emit = () => {const t =read();const key =JSON.stringify(t);if (key !== last) { last = key;notify(t); } };const update = () => { emit();setTimeout(emit,100);setTimeout(emit,400); };update();const observer =newMutationObserver(update); observer.observe(document.body, {attributes:true,attributeFilter: ["class"]});return () => observer.disconnect();})
plotStyle = ({// "inherit" takes the page's text color directly, so axes and labels follow a theme// switch even before the plot redraws.color:"inherit",background:"transparent",fontSize:"13px",overflow:"visible"})
themedButton = (label, counterLabel =null) => {const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">${label}</button>`;// The counter shows which run is on screen, so every press visibly does something and a// reader can tell runs apart. It reads 1 at page load and after Reset.const counter = counterLabel?html`<span class="bisc-run-counter" aria-live="polite"></span>`:null;const form =html`<form class="bisc-explorer-control">${button}${counter ||""}</form>`;const show = () => { if (counter) counter.textContent=`${counterLabel}${form.value+1}`; }; form.value=0;show(); button.onclick= () => { form.value+=1; form.dispatchEvent(newEvent("input", {bubbles:true})); };// Reset sets the value back to 0 and dispatches input; refresh the counter either way. form.addEventListener("input", show);return form;}
resetButton = (controls, label ="Reset to the starting values") => {// This runs once per page, because the cell that calls it depends on the controls// themselves (viewof), not on their values; so these are the values at page load.const start = controls.map(c => c.value);const button =html`<button type="button" class="btn btn-sm btn-outline-primary bisc-explorer-button">${label}</button>`; button.onclick= () => { controls.forEach((c, k) => { c.value= start[k]; c.dispatchEvent(newEvent("input", {bubbles:true})); }); };returnhtml`<div style="margin: 0.5rem 0">${button}</div>`;}
// A small seeded generator (mulberry32), so a run can be repeated.makeRandom = (seed) => {let a = seed >>>0;return () => { a = (a +0x6D2B79F5) >>>0;let t = a; t =Math.imul(t ^ (t >>>15), t |1); t ^= t +Math.imul(t ^ (t >>>7), t |61);return ((t ^ (t >>>14)) >>>0) /4294967296; };}
This explorer reads the count interval off an error rate, as Chapter 2 does. A record, once verified correct, goes wrong with probability \(p\) in any month and stays wrong until the next count finds it. Counted every \(n\) months, its average accuracy over the count cycle is
Choose the error rate and the accuracy target, and the page finds the longest interval that still holds the target. The page runs in your browser and records nothing.
{const show = d3.range(1,Math.max(6, best +2) +1);const a4 =accuracy(p,4);returnhtml`<p>At p = ${pPct.toFixed(1)}% a month, ${best >=1?html`the longest interval that holds ${targetPct.toFixed(1)}% is <strong>${best} month${best ===1?"":"s"}</strong>, which is${(12/ best).toFixed(best ===12||12% best ===0?0:1)} counts a year. Counting every ${best +1} months gives ${(100*accuracy(p, best +1)).toFixed(1)}%, below the target.`:html`even a monthly count falls short of ${targetPct.toFixed(1)}%.`}</p> <div style="overflow-x: auto; max-width: 100%"> <table class="table table-sm" style="white-space: nowrap"> <thead><tr><th>n months</th>${show.map(n =>html`<th style="text-align: right">${n}</th>`)}</tr></thead> <tbody><tr><td>A(n)</td>${show.map(n =>html`<td style="text-align: right; ${n === best ?"font-weight: 700":""}">${(100*accuracy(p, n)).toFixed(1)}%</td>`)}</tr></tbody> </table></div> <p>One entry in full: A(4) = (1 − ${(1- p).toFixed(3)}<sup>4</sup>)/(4 × ${p.toFixed(3)}) = ${(1-Math.pow(1- p,4)).toFixed(4)}/${(4* p).toFixed(3)} = ${a4.toFixed(3)}. The other entries repeat the computation with n changed.</p>`;}
The plot draws \(A(n)\) for your error rate and for half and twice it, with the target as a dashed line. The blue dot is the longest interval that holds the target at your error rate. Notice that doubling the error rate roughly halves the interval that holds the target.
{const rates = [p /2, p,Math.min(0.99,2* p)];const name = q =>`p = ${(100* q).toFixed(2).replace(/\.?0+$/,"")}%`;const rows = rates.flatMap(q => d3.range(1,25).map(n => ({n,A:100*accuracy(q, n),p:name(q)})));return Plot.plot({style: plotStyle,height:260,marginLeft:55,marginBottom:45,x: {label:"Months between counts",labelAnchor:"center",labelOffset:38,grid:true},y: {label:"Average accuracy (%)",grid:true,domain: [Math.min(80, targetPct -2),100]},color: {domain: rates.map(name),range: [theme.muted, theme.primary, theme.accent],legend:true},marks: [ Plot.ruleY([targetPct], {stroke: theme.muted,strokeDasharray:"5,3"}), Plot.line(rows, {x:"n",y:"A",stroke:"p",strokeWidth:1.5,clip:true}), best >=1? Plot.dot([{n: best,A:100*accuracy(p, best)}], {x:"n",y:"A",r:6,fill: theme.primary}) :null ],ariaLabel:"Average accuracy against the count interval",ariaDescription:`At p = ${pPct}% the longest interval holding ${targetPct}% is ${best} months.` });}
Things to Try
Start at the chapter’s item, \(p = 3\%\) and a 95% target. \(A(4) = 95.6\%\) and \(A(5) = 94.2\%\), so the item is counted every four months, three times a year.
Double the error rate to 6%. \(A(2) = 97.0\%\) and \(A(3) = 94.1\%\), so the item needs counting every two months, six times a year.
Read the curves of the chapter’s figure: at 1% the interval is 11 months, at 2% it is 6, and at 4% it is 3.
Hold \(p = 3\%\) and move the target. At 90% the interval stretches to 8 months; at 98% it shrinks to 2. The target, not the item’s dollar value, sets the interval once the error rate is known.
Check What You Found
Check what you found
1. Two items are both in class A, and both must hold 95% average record accuracy. One goes wrong with probability 3% a month and the other 6%. How often should each be counted?