Release Schedule 5: How Many Runs Is Enough
Uses Only Free-Tier SpiceGrinder
Problem statement
Every answer in the last three lessons came from a million trials. Why a million? Too few trials and the answer is mostly noise; too many and we wait for precision we don’t need. We want a rule, not a habit.
The question: for the correlated release model of lesson 4, we estimate the chance of finishing after day 40 as the share of trials that were late. How many trials does that estimate need to be good to within one percentage point? To within a tenth of a point?
The model
There is no new model: we use samples/simulation/release-schedule-correlated.xml from lesson 4, and the Late column (the last one) as our estimate. What is new is repetition. One run gives one estimate; to see how much an estimate wanders, we run the same model again with a different seed and compare. A different seed is a fresh, independent batch of trials from the same model, which is exactly what a replication is.
A shell loop does it, with the share of late rows computed from column 6 of each run (the loop shown is for a Unix shell; any scripting language works the same way):
for s in $(seq 1 30); do
grind --count 1000 --seed $s release-schedule-correlated.xml | awk -F, '{late += $6} END {print late / NR}'
done
Thirty runs of 1,000 rows each, seeds 1 to 30. The first ten estimates (run the same seeds and you get exactly these):
seed 1 2 3 4 5 6 7 8 9 10
0.194 0.189 0.168 0.187 0.182 0.175 0.190 0.192 0.203 0.194
If you don’t want to choose the seeds, grind --no-seed ... lets SpiceGrinder pick a fresh one on every run and prints the seed it used (on its standard error stream, as a line beginning Seed:), so a run you like can be repeated later with --seed. Seed 0 means the same as no seed.
We do this at four run sizes: 30 estimates each at 1,000, 10,000, 100,000 and 1,000,000 rows, with the same seeds 1 to 30.
Thirty estimates
The dots at 1,000 rows run from 16.0% to 20.4%. At a million rows they sit in a line: from 18.53% to 18.67%. The center doesn’t move; only the spread does:
| Rows per run (n) | Mean of the 30 | Spread of the 30 (standard deviation) | Formula sqrt(p(1-p)/n) | Range of the 30 | Inside the band |
|---|---|---|---|---|---|
| 1,000 | 0.1861 | 0.0121 | 0.0123 | 0.1600 to 0.2040 | 29 of 30 |
| 10,000 | 0.1861 | 0.0040 | 0.0039 | 0.1770 to 0.1934 | 29 of 30 |
| 100,000 | 0.1861 | 0.0013 | 0.0012 | 0.1834 to 0.1881 | 28 of 30 |
| 1,000,000 | 0.1861 | 0.0003 | 0.0004 | 0.1853 to 0.1867 | 29 of 30 |
The reference value p is 0.18609, the mean of the thirty 1,000,000-row estimates (a standard error of 0.00007). Our lesson 4 run, with the model’s own seed, gave 0.1866, within 1.3 standard errors of it.
The spread follows the formula you already met in lesson 1: for an estimated probability p from n independent trials, the standard error is sqrt(p(1-p)/n). It falls with the square root of n, so a hundred times the rows buys ten times the precision. The spread of 30 numbers is itself only known to about 13%, so ratios from 0.8 to 1.1 against the formula, as in the table, are what we should expect. The band in the figure is p plus or minus 1.96 standard errors, a 95% interval, and 28 or 29 of 30 estimates landing inside it is what 95% predicts (28.5 on average).
How many rows do we need?
Turn the formula around. If we want a 95% interval of plus or minus h, we need 1.96 × sqrt(p(1-p)/n) = h, so
n = 1.96² × p(1−p) / h²
With p = 0.18609:
| Precision (95%) | Rows needed |
|---|---|
| plus or minus 1 point (h = 0.01) | 5,819 |
| plus or minus 0.1 point (h = 0.001) | 581,841 |
Ten times the precision costs a hundred times the rows. Do the formulas deliver? We reran each size with 200 fresh seeds (1001 to 1200) and counted how many estimates landed within h of p:
| Rows | Within plus or minus h | Spread of the 200 | Formula |
|---|---|---|---|
| 5,819 (h = 0.01) | 96.5% of the 200 | 0.00511 | 0.00510 |
| 581,841 (h = 0.001) | 95.0% of the 200 | 0.00053 | 0.00051 |
Both are consistent with 95% (the standard error of such a fraction from 200 runs is about 1.5 points, so 96.5% is one standard error high and 95.0% is right on it).
Rows are cheap here: a million of them take about 1.3 seconds including the Java start-up, so even the plus-or-minus 0.1 point interval costs less than a second. A million rows give a 95% interval of plus or minus 0.076 points, which is why it has been a comfortable default. The companion page lets you choose a run size and see the thirty real estimates against the band, and gives a small calculator for the rows needed at any precision, with the measured confirmation beside it.
Two cautions. If you don’t know p yet, the worst case is p = 0.5, which needs n = 0.9604 / h², about 9,604 rows for plus or minus 1 point; and this formula is for a probability. A mean has its own, simpler rule (the spread of the quantity divided by the square root of n), and a percentile has a different one, so check them separately. The second caution is about what the precision is worth. A million rows pin the estimate down to a tenth of a point, but the model’s inputs are not that exact. In lesson 4 the same model gave 0.168 with a correlation of 0.3 and 0.203 with a correlation of 0.9, a swing of 3.5 points from a number we guessed. Past the point where simulation noise is small against the uncertainty in the inputs, more rows buy a precision the model doesn’t have.
Check: do the numbers match the math?
The formula predicts the spread at every run size, and the table shows it does, to within about 20% (ratios of 0.99, 1.02, 1.09 and 0.80), which is as close as a spread measured from 30 numbers can be expected to come. The rows-needed formula can be checked by hand: for plus or minus 1 point, n = 1.96² × p(1−p) / 0.01² = 3.8416 × 0.1861 × 0.8139 / 0.0001 ≈ 5,819. The 200-seed reruns, which don’t use the formula at all, found the intervals it promised: 96.5% and 95.0% of the estimates within plus or minus 1 point and 0.1 point, against 95% expected.
What this gives you: a way to measure an estimate’s noise directly, by rerunning with other seeds; a formula that predicts that noise (sqrt(p(1-p)/n)) and turns into a row count for any precision you want; and the sense that the square-root law is why each extra digit is expensive, and why it eventually stops being worth buying.
That finishes the first module. We built a schedule, gave its tasks distributions, joined them with dependencies and correlation, and learned how much to trust the answer. In every one of those lessons a row was one project, finished all at once. The next module starts a different kind of row: one that is a whole path through time, a startup’s cash balance month by month, and asks how long the money lasts.