13.12 Probability problem set, part d: hypothesis tests, regression, queueing, balls into bins
There comes a point where a system starts making claims and serving load at the same time. Hypothesis tests: paired and two-sample permutation, McNemar, Holm turns “model B is better” into a p-value, and Logistic regression (IRLS), ROC-AUC, calibration (ECE) fits and scores the gateway’s policy classifier; both are short functions whose results are easy to misread. Later, the gateway routes requests across engine replicas and a load generator measures latency, and two pieces of probability decide whether those numbers make sense: Little’s law, which links throughput, latency, and concurrency, and the balls-into-bins arithmetic behind random and two-choice load balancing.
Concepts from other sections (11)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- p-value: the probability under the null of a statistic at least as extreme as the one observed. Read more: 13.6 Hypothesis tests: paired and two-sample permutation, McNemar, Holm
- AUC: the area under the ROC curve, equal to the probability that a random positive outscores a random negative, ties counting half. Read more: 13.8 Logistic regression (IRLS), ROC-AUC, calibration (ECE)
- Linearity of expectation: , which holds even when and are dependent; it is the main tool for analysing randomized algorithms, such as the coupon collector’s expected draws. Read more: Chapter 13: Probability and Statistics
- Paired difference: the score of a template with one group term minus its score with the other, so template effects cancel. Read more: 36.1 Bias and safety evals in AI Engineering
- sigmoid: , mapping the real line into , with . Read more: 7.3 Activation Functions and Their Derivatives
- Partial derivative: the ordinary derivative of along one coordinate with every other coordinate frozen. Read more: 10.1 Partial derivatives, gradients, and gradcheck
- Logistic regression: a model in which the log-odds are linear in the features. Read more: 13.8 Logistic regression (IRLS), ROC-AUC, calibration (ECE)
- Chain rule: . Read more: 10.2 Jacobians, the multivariable chain rule, and numeric JVP/VJP
- Log-likelihood: , the log probability of the observed counts under a distribution . Read more: 13.3 MLE, Laplace, absolute discounting
- Hessian: the symmetric matrix of second partial derivatives, whose eigenvalues classify a critical point. Read more: 10.3 Calculus 3 problem set: vectors, gradients, the chain rule, Hessians, multiple integrals, Lagrange
- IRLS: iteratively reweighted least squares, Newton’s method on the logistic loss, where each step is a weighted least-squares solve with weights . Read more: 13.8 Logistic regression (IRLS), ROC-AUC, calibration (ECE)
This problem set works each idea once by hand, so the code and the dashboards that follow are transcriptions of things you have already computed. It is a pen-and-paper set with 19 answers (counting lettered parts) and one proof. A short review and three examples by hand come first; then the problems, each followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. Try each problem before opening its answer. Read it alongside the hypothesis-tests and logistic-regression sections: Problems 1 to 4 are their tests by hand, Problems 5 to 9 the regression behind the policy head, and Problems 10 to 17 the queueing and load-balancing arithmetic that the load generator and the gateway’s router rely on.
The set builds on the sampling distributions of problem set C and on the hypothesis-testing and regression material in the chapter opening.
Learning objectives
- Compute exact permutation, sign-flip, and McNemar p-values by enumeration, and apply Holm’s correction.
- Fit a least-squares line by hand, interpret a logistic coefficient as a log odds ratio, and derive the logistic loss gradient.
- Compute an AUC with ties and prove that the penalized logistic loss is convex.
- Apply Little’s law and the M/M/1 formulas to relate arrival rate, utilization, concurrency, and latency.
- Use linearity of expectation for empty bins and collisions, and state the power-of-two-choices bound.
Notation
Section titled “Notation”The set uses these symbols.
| Symbol | Meaning | Type / shape |
|---|---|---|
| , | paired differences and random signs | reals |
| , | discordant counts (only A right, only B right) | integers |
| , , | sorted p-values, family size, level | reals, integer |
| , | intercept and slope of a least-squares line | reals |
| the sigmoid | function | |
(lam), (mu) | arrival rate and service rate | positive reals |
| utilization | in | |
| , | mean number in the system and mean time in the system | reals |
| , | bins and balls | positive integers |
A p-value is the probability under of a statistic at least as extreme as observed. Exact permutation p-values count the relabellings that makes equally likely: sign vectors for pairs, splits for two samples. McNemar uses only the discordant pairs, each a fair coin under . Holm sorts the p-values and rejects the -th smallest while (with counted from 0).
Regression
Section titled “Regression”Least squares minimizes ; setting both partial derivatives to 0 gives with , , and . In logistic regression the log-odds are linear, so a coefficient multiplies the odds by per unit of its feature, and . The AUC is the fraction of (positive, negative) pairs ranked correctly, ties counting one half.
Queueing
Section titled “Queueing”The second half of the set leaves statistics for systems. Little’s law says that in any system where items arrive at long-run rate and stay a mean time , the mean number inside is , whatever the arrival or service distributions. The proof is an area argument: the area under “number inside over time” counts each item’s time inside once. In the M/M/1 queue (Poisson arrivals, exponential service, one server), the number in the system is geometric, , so and, by Little, .
Balls into bins
Section titled “Balls into bins”With balls thrown uniformly into bins, a given bin is missed by every ball with probability , and linearity of expectation adds such indicators over bins or over pairs of balls with no independence needed. With , . The most loaded bin holds about balls with one random choice; Azar, Broder, Karlin, and Upfal (1994) showed that sampling two bins and taking the emptier gives , an exponential improvement.
Three examples by hand
Section titled “Three examples by hand”These are siblings of Problems 2, 11, and 14, not problems of the set.
A two-sample p-value. Take and , so . The six ways to pick group from give of , , , , , . Two of six reach 3: .
An M/M/1 queue. With and per second, , , and s, and indeed . The service time alone is s; queueing quadrupled it.
Empty bins. Throw balls into 3 bins. A bin is empty with probability , so the expected number of empty bins is . Enumerating the 27 assignments agrees: 6 hit every bin (0 empty), 18 leave one empty, 3 leave two empty, and .
The problems
Section titled “The problems” is written lam and is mu in formulas; answers are exact (, ), not decimals. Lettered parts are answered separately, and the tag after each problem says what kind of answer is expected.
Hypothesis tests
Section titled “Hypothesis tests”The first four problems compute each test of the hypothesis-tests section by exhaustive enumeration.
Problem 1. Model B minus model A on three prompts gives the paired differences . Give the exact two-sided sign-flip p-value: the fraction of the sign vectors with . [number, exact]
Answer
. . Of the sign vectors, only and give ; every other pattern flips at least one term and lands at 0, 2, or 4. So : with three pairs, even a unanimous win cannot reach . Common mistakes: , the one-sided count (only ); , the add-one Monte Carlo estimate , which the hypothesis-tests section uses when it samples, not the exact enumeration asked here.
Problem 2. Two unpaired samples, and , with statistic . Give the exact two-sided permutation p-value: the fraction of the ways to split the pooled values into two groups of two whose is at least the observed one. [number, exact]
Answer
. Observed . The six ways to choose group from give : , , , , , . Two of six reach 2.5, so . Common mistakes: , the one-sided count ( only); .
Problem 3. Two classifiers on the same eval set: A alone is right on examples, B alone on . Give the exact two-sided McNemar p-value , , . [number, exact]
Answer
(). , . The tail is out of , doubled for two sides: . Under the null, each discordant example is a fair coin between A and B, which is why only the disagreements matter. Common mistakes: , the tail not doubled; , a tail that stops at and leaves out the observed count.
Problem 4. Five comparisons have p-values . Which hypotheses does Holm’s procedure reject at family-wise level ? Answer with the set of their indices. [set]
Answer
. Sort: , , , , . Holm compares the -th smallest with : (reject 2); (reject 4); : stop, and keep every remaining hypothesis, including . Common mistakes: , Bonferroni (every p against ), valid but weaker; , no correction; , a step-down that does not stop at the first failure: once fails its bar, every larger p-value is kept.
Regression
Section titled “Regression”The next five problems are the regression behind the policy head: a least-squares line, odds, the loss gradient, an AUC with a tie, and the convexity proof.
Problem 5. Fit the least-squares line to the points . (a) . [number, exact] (b) . [number, exact]
Answer
(a) . (b) . , . With deviations and : and . (a) . (b) The line passes through : . Common mistakes: , the reciprocal of the slope from regressing on ; , the slope through the two end points; for (b), the first ; for (b), .
Problem 6. A fitted logistic regression has log-odds . By what factor do the odds of multiply when increases by 2? [number, exact]
Answer
. The log-odds grow by , so the odds multiply by . A logistic coefficient is a log odds ratio per unit of . Common mistakes: , the factor for one unit; , the change in log-odds reported as if it were the odds factor.
Problem 7. For one example with , , and , the loss is . Give . [expr in w, x, y]
Answer
((1/(1 + exp(-w*x)) - y)*x). Let . Using and , , so . The chain rule multiplies by . Prediction minus label, times the input. Common mistakes: , the gradient of the log-likelihood rather than of the loss (a step along it walks uphill on the loss); , the chain-rule factor missing.
Problem 8. A classifier scores three positives and three negatives . Give its ROC-AUC, counting a tied pair as one half. [number, exact]
Answer
. There are positive-negative pairs. beats all three negatives (3); beats and (2); beats and ties (1.5). AUC . Common mistakes: , the tie counted as a loss; , the tie counted as a win.
Problem 9. Prove that the penalized logistic loss , , , is convex, and say why that makes every stationary point a global minimum and Newton’s step well defined when . [proof]
Answer
Setup. Examples , , with , ; is the matrix with rows ; , , the vector of the ; .
Gradient and Hessian. With , each term is , so (Problem 7) and, since , . By the chain rule,
Positive semidefinite. For every , since makes every weight positive. When and the last term is strictly positive, so is positive definite.
Conclusion. A twice-differentiable function with a positive semidefinite Hessian everywhere is convex, so is convex (strictly when ). For convex differentiable , for all , so a point with has for every : a global minimum, unique when . Newton’s step solves ; with , is positive definite, hence invertible, so the system has exactly one solution. This is why the IRLS fitter of Logistic regression (IRLS), ROC-AUC, calibration (ECE) converges.
A complete proof derives the gradient and Hessian, shows from , draws both conclusions, and defines every symbol. The model proof is also in course/solutions/solve/S-M07d/q9.md.
Queueing and Little’s law
Section titled “Queueing and Little’s law”The next four problems move from statistics to systems: concurrency from throughput and latency, and how latency grows as a server fills.
Problem 10. A gateway receives requests per second and the mean time a request spends inside it is s. By Little’s law, how many requests are inside on average? [number, exact]
Answer
. requests in flight on average. Little’s law needs only a stable system, no distributional assumption. Common mistakes: ; .
Problem 11. A single-server queue with Poisson arrivals at per second and exponential service at rate per second (M/M/1). (a) The utilization . [number, exact] (b) The mean number in the system . [number, exact] (c) The mean time in the system , by Little’s law. [number, exact]
Answer
(a) . (b) . (c) s. (a) . (b) . (c) s, which agrees with . Common mistakes: for (a); for (b), the utilization reported as the number in system; for (b), the number waiting in queue without the one in service; for (c), the service time alone; for (c), the queue wait without the service.
Problem 12. Give the mean time in an M/M/1 system as a formula in the arrival rate and the service rate . [expr in lam, mu]
Answer
(1/(mu - lam)). , and Little’s law gives . Common mistakes: , the service time with no queueing; , which is , not .
Problem 13. Keep the service rate fixed. By what factor is the mean time in an M/M/1 system larger at utilization than at ? [number, exact]
Answer
. , so with fixed the ratio is . Going from half to 90% busy multiplies latency by five; this is the curve behind keeping a server below saturation. Common mistakes: , the ratio of the utilizations; , the ratio of values ( against ), which compares counts, not times (the arrival rates differ).
Balls into bins
Section titled “Balls into bins”The last four problems are the load-balancing arithmetic: empty bins, collisions, and the power of two choices.
Problem 14. Throw balls independently and uniformly into bins. Give the expected number of empty bins. [expr in n]
Answer
. A given bin is missed by one ball with probability and by all independent balls with probability . Linearity of expectation adds this indicator over the bins, with no independence between bins needed. Common mistakes: , the probability for one bin, not the expected count; , the large- limit, not the exact value.
Problem 15. As , what fraction of the bins in Problem 14 is empty? [number, exact]
Answer
(). The fraction is . Common mistakes: 0; , the occupied fraction.
Problem 16. Throw balls independently and uniformly into bins. Give the expected number of pairs of balls that land in the same bin. [expr in m, n]
Answer
. Each of the unordered pairs of distinct balls lands in the same bin with probability (the second ball matches the first’s bin); linearity adds them. This is the birthday problem: collisions appear once . Common mistakes: , counting ordered pairs and self-pairs; , the mean load, not the collisions.
Problem 17. requests go to servers. Each request either picks one server uniformly at random, or samples two servers and joins the less loaded one (the power of two choices). With high probability the maximum load grows like: [choice]
(a) with two choices, the same as with one.
(b) with two choices, against with one.
(c) with one choice, with two.
(d) a constant with two choices.
Answer
(b). With one uniform choice the fullest bin holds about ; with the less loaded of two random choices it holds (Azar, Broder, Karlin, and Upfal), an exponential improvement. Common mistakes: (a), believing the second choice only shaves a constant; (d), a constant: the bound still grows, just very slowly; (c) has the wrong rates for both.
What can go wrong
Section titled “What can go wrong”In the tests, the commonest slip is a one-sided count for a two-sided question, which halves ; count both tails, or double the binomial tail (Problems 1, 2, and 3). Quoting the add-one Monte Carlo estimate where the exact was asked gives 1/3 instead of 1/4; enumerate all sign vectors (Problem 1). Using Bonferroni, no correction, or a Holm that does not stop gives the wrong set of discoveries; sort, compare with , and stop at the first failure (Problem 4).
The regression slips change the answer’s scale or sign. Regressing on , or drawing a line through two points, gives a different slope; use over all four points (Problem 5). Reporting the change in log-odds as the odds factor gives 1 instead of ; exponentiate the change (Problem 6). Counting ties as wins or losses gives 7/9 or 2/3 instead of 13/18; a tie counts one half (Problem 8).
Warning: Taking the likelihood’s gradient instead of the loss’s makes Newton walk uphill, and dropping the chain-rule factor gives the wrong scale. Differentiate the loss: (Problem 7).
The queueing slips mix up the three quantities of Little’s law. Computing instead of gives 160 requests, and reporting the utilization as gives 4/5; use and (Problems 10 and 11). Reporting the service time or the queue wait as the time in system gives 1/10 or 2/5 s; is wait plus service (Problem 11c).
In balls into bins, giving the limit where the exact count was asked is approximate where exact was wanted; keep (Problem 14). Counting ordered pairs or self-pairs gives collisions; count unordered pairs (Problem 16). And believing two choices only shave a constant leads to answer (a); the bound drops from to (Problem 17).
Where this leads
Section titled “Where this leads”This set reads the sampling distributions and intervals of problem set C as tests. Hypothesis tests: paired and two-sample permutation, McNemar, Holm implements paired_permutation_test, permutation_test, mcnemar, and holm, which are Problems 1 to 4 in code, and Logistic regression (IRLS), ROC-AUC, calibration (ECE) implements IRLS and roc_auc and relies on the convexity of Problem 9. In AI Engineering, the comparison table of The evaluation harness and the model zoo runs Problems 1 to 4 at scale, and the open-loop load generator reports concurrency, throughput, and latency, tied together by Little’s law. In AI Engineering, Routing, cascades, and failover routes across replicas with random choice against least-loaded of two.
Further reading
Section titled “Further reading”- Wasserman, All of Statistics, ch. 10 and 13.
- Harchol-Balter, Performance Modeling and Design of Computer Systems, ch. 6 (Little’s law) and 14 (M/M/1).
- Mitzenmacher and Upfal, Probability and Computing, ch. 5 (balls and bins) and 17 (the power of two choices).
Key terms
Section titled “Key terms”- Exact permutation p-value: the fraction of equally likely relabellings under whose statistic is at least as extreme as observed.
- McNemar test: an exact binomial test on the discordant pairs of two classifiers evaluated on the same examples.
- Holm’s procedure: a step-down correction that compares the sorted p-values with and stops at the first failure.
- Log odds ratio: a logistic coefficient; increasing its feature by one multiplies the odds by .
- Little’s law: for any stable system.
- Utilization: , the fraction of time a server is busy.
- Power of two choices: sampling two bins and joining the emptier, which cuts the maximum load from to .
Summary
Section titled “Summary”- An exact permutation p-value is a count over a finite set of relabellings; with three pairs, even a unanimous win has (Problems 1 and 2).
- Holm stops at the first p-value above its bar and still rejects more than Bonferroni (Problem 4).
- A logistic coefficient is a log odds ratio, and the loss gradient is “prediction minus label, times the input” (Problems 6 and 7); that loss is convex, which is why IRLS converges (Problem 9).
- Little’s law holds for any stable system; in M/M/1 the time in system explodes as utilization approaches 1 (Problems 10 to 13).
- Throwing balls into bins leaves about of them empty, and asking two bins instead of one shrinks the fullest bin from to (Problems 14 to 17).