A factory numbers its tanks 1, 2, ..., N; you capture n of them, chosen at random, and read the serial numbers. How many tanks were built? The largest serial number xmax is a lower bound for N and it is too small on average; the estimate (n + 1)/n · xmax − 1 (blue) repairs that exactly, with spread (N + 1)(N − n)/(n(n + 2)) in variance. The obvious alternative, twice the sample mean minus 1 (pink), is also unbiased but has a larger variance by the factor (n + 2)/3. Each preset simulates R captures for the chosen N and n; the top panel shows the two sampling distributions around the true N, the bottom panel the exact standard deviation of each estimator against n.
Serial numbers are drawn without replacement and uniformly from 1, ..., N, as in Case Study 1.2.3 of Larsen and Marx (2018), where five captured tanks bear 92, 14, 28, 300 and 146 and the estimate is 359. The simulation uses a seeded generator, so the same settings always give the same histogram; New simulation changes the seed. If n exceeds N it is lowered to N.
code/ch01_introduction.py (tank_est, tank_var_est, tank_var_mom).