Unit 13, lesson 83

A Discrete Probability Investigation

How to specify an inspection model, build its joint table from conditional rates, count alerts with a binomial law, find conditional expected work, test assumption sensitivity and compare predictions with simulated output.

  • Video 83
  • Complete Model Investigations

An automated inspection raises an alert on some items, and every alerted item gets a manual review. How often will it alert, how likely is an alerted item to be faulty, how many alerts will ten items produce, and how many minutes of review does an item cost on average? None of these questions has an answer until a model is written down. This lesson specifies one complete model, derives each answer exactly from it, and then asks which answers change when an input or an assumption changes. All rates and times on this page are constructed for illustration.

Key terms

Model specification

Definition A model specification lists everything a probability investigation assumes before it calculates. It names the experiment and its possible outcomes, the events and random variables, the support of each random variable, the numerical inputs, and the assumptions that connect them, such as which events are independent and how repeated items relate to one another. It is complete for a question when every probability and expectation that the question needs is determined by what it lists. Quantities computed from the specification, such as an overall alert rate, are outputs, so they are not free to be chosen separately.

In plain words Write the model down first and calculate second. Every answer that follows is a statement about this model, so it is only as trustworthy as the listed inputs and assumptions, and an assumption left unstated is still an assumption.

Example The inspection model of this page has four parts.

  • One item either has a fault or not, and its inspection either raises an alert or not. The events are FF, the item has a fault, and AA, the inspection raises an alert, and the sample space consists of the four combinations of FF or FcF^{c} with AA or AcA^{c}.
  • The inputs are P(F)=0.1P(F) = 0.1, P(A∣F)=0.8P(A \mid F) = 0.8 and P(A∣Fc)=0.2P(A \mid F^{c}) = 0.2. Both conditional rates are defined because 0<P(F)<10 < P(F) < 1.
  • The review time RR of one item, in minutes, is 1212 for a faulty alerted item and 33 for a nonfaulty alerted item. An item without an alert gets no review, so R=0R = 0 on AcA^{c} and the support of RR is {0,3,12}\{0, 3, 12\}.
  • Questions about several items assume that the items are independent copies of the one-item model.

Within one item, fault and alert are dependent on purpose, since an alert is four times as likely for a faulty item as for a nonfaulty one. Independence across items is a separate assumption, and the binomial count of alerts below needs it.

Joint model from conditional rates

Definition Let FF and AA be events with 0<P(F)<10 < P(F) < 1, and suppose the inputs are P(F)P(F), P(A∣F)P(A \mid F) and P(A∣Fc)P(A \mid F^{c}). The multiplication rule gives the four joint probabilities, for example P(F∩A)=P(A∣F) P(F)P(F \cap A) = P(A \mid F)\,P(F) and P(F∩Ac)=P(Ac∣F) P(F)P(F \cap A^{c}) = P(A^{c} \mid F)\,P(F), where P(Ac∣F)=1−P(A∣F)P(A^{c} \mid F) = 1 - P(A \mid F). These four numbers are nonnegative and add to 11, so they determine the probability of every event built from FF and AA. The law of total probability over the partition FF, FcF^{c} gives

P(A)=P(A∣F) P(F)+P(A∣Fc) P(Fc),\begin{aligned} P(A) &= P(A \mid F)\,P(F) \\[0.4em] &\quad + P(A \mid F^{c})\,P(F^{c}), \end{aligned}

and when P(A)>0P(A) > 0, Bayes’ theorem gives P(F∣A)=P(A∣F) P(F)/P(A)P(F \mid A) = P(A \mid F)\,P(F)/P(A), which is the joint probability P(F∩A)P(F \cap A) divided by P(A)P(A).

In plain words The conditional rates describe the faulty group and the nonfaulty group one at a time. Weighting each rate by the probability of its group gives the joint table, and every other probability of the model, including the reverse conditional probability of a fault given an alert, is read from that table.

Example For the inspection model the joint table is below.

AAAcA^{c}Total
FF0.080.080.020.020.10.1
FcF^{c}0.180.180.720.720.90.9
Total0.260.260.740.7411

The alert column gives P(A)=0.8⋅0.1+0.2⋅0.9=0.26P(A) = 0.8 \cdot 0.1 + 0.2 \cdot 0.9 = 0.26, and

P(F∣A)=0.080.26=413,P(F \mid A) = \frac{0.08}{0.26} = \frac{4}{13},

about 0.30770.3077. An alert raises the fault probability from 0.10.1 to about 0.310.31, but a fault is still far from certain. The nonfaulty alert cell 0.180.18 is more than twice the faulty alert cell 0.080.08, so 9/139/13 of the alert probability, about 69 percent, comes from nonfaulty items. That does not contradict the alert rate of 80 percent among faulty items, which conditions on a different group. The lesson Bayes’ Theorem and Base Rates treats this reversal in detail.

Binomial count of alerts

Definition Let items 1,…,n1, \dots, n be independent copies of the one-item model, let IiI_i be the indicator that item ii raises an alert, and let p=P(A)p = P(A). The number of alerts N=I1+⋯+InN = I_1 + \dots + I_n then satisfies N∼Bin⁡(n,p)N \sim \operatorname{Bin}(n, p), with

pN(k)=(nk)pk(1−p)n−kp_N(k) = \binom{n}{k} p^{k} (1 - p)^{n - k}

for k=0,1,…,nk = 0, 1, \dots, n, and E[N]=npE[N] = np and Var⁡(N)=np(1−p)\operatorname{Var}(N) = np(1 - p). The mean npnp needs only that each item has alert probability pp, by linearity of expectation. The binomial probabilities, the variance formula and the product P(N=0)=(1−p)nP(N = 0) = (1 - p)^{n} use the independence of the items and can fail without it.

In plain words Each item is one trial whose alert probability, after averaging over faulty and nonfaulty items, is 0.260.26, and independent items make the count binomial. The expected count is a probability-weighted average over possible batches, so it need not be a whole number, while every actual batch has a whole-number count.

Example For ten items, N∼Bin⁡(10,0.26)N \sim \operatorname{Bin}(10, 0.26), with E[N]=2.6E[N] = 2.6 and Var⁡(N)=10⋅0.26⋅0.74=1.924\operatorname{Var}(N) = 10 \cdot 0.26 \cdot 0.74 = 1.924, so SD⁡(N)≈1.387\operatorname{SD}(N) \approx 1.387. The probability of at least one alert is

P(N≥1)=1−0.7410≈0.9508.\begin{aligned} P(N \ge 1) &= 1 - 0.74^{10} \\[0.4em] &\approx 0.9508. \end{aligned}

No batch shows 2.62.6 alerts. The most likely count is 22, with probability about 0.2740.274, followed by 33, with probability about 0.2560.256.

Conditional expected work

Definition Let RR be the review time of one item, as in the specification. For an event BB with P(B)>0P(B) > 0, the conditional expectation of RR given BB is

E[R∣B]=∑rr P(R=r∣B),\begin{aligned} &E[R \mid B] \\[0.4em] &\quad = \sum_{r} r\,P(R = r \mid B), \end{aligned}

where the sum runs over the possible values 00, 33 and 1212. If 0<P(A)<10 < P(A) < 1, the law of total expectation gives

E[R]=E[R∣A] P(A)+E[R∣Ac] P(Ac).\begin{aligned} E[R] &= E[R \mid A]\,P(A) \\[0.4em] &\quad + E[R \mid A^{c}]\,P(A^{c}). \end{aligned}

In plain words The same review time can be averaged over two different groups. The conditional mean E[R∣A]E[R \mid A] is minutes per alerted item, and the unconditional mean E[R]E[R] is minutes per inspected item, with or without an alert. Keep the group with the number, because here the two answers differ by the factor P(A)P(A).

Example Among alerted items the fault fraction is 4/134/13 and the nonfault fraction is 9/139/13, so

E[R∣A]=12⋅413+3⋅913=7513≈5.769\begin{aligned} E[R \mid A] &= 12 \cdot \frac{4}{13} + 3 \cdot \frac{9}{13} \\[0.4em] &= \frac{75}{13} \approx 5.769 \end{aligned}

minutes per alerted item. Items without an alert get no review, so E[R∣Ac]=0E[R \mid A^{c}] = 0 and

E[R]=0.26⋅7513=1.5E[R] = 0.26 \cdot \frac{75}{13} = 1.5

minutes per item. The joint table gives the same result directly, since 12⋅0.08+3⋅0.18=0.96+0.54=1.512 \cdot 0.08 + 3 \cdot 0.18 = 0.96 + 0.54 = 1.5. For ten items that each follow the one-item model, linearity gives 1515 minutes of review on average, whether or not the items are independent. This is expected work. It is not elapsed clock time or a staffing need, which would depend on parallel reviewers, queues and variable review times that the model leaves out.

Assumption sensitivity

Definition Assumption sensitivity is the way a model’s outputs respond when one input or one assumption is changed and the rest of the specification is held fixed. A sensitivity check recalculates every output under the change and records which conclusions move, by how much, and which stay the same.

In plain words The algebra of a model can be exactly right while its inputs are uncertain. Changing one input at a time shows which answers rest heavily on that input, and changing one assumption shows which answers needed it.

Example Suppose faults are twice as common, with P(F)=0.2P(F) = 0.2, while both alert rates stay the same. The alert cells become 0.8⋅0.2=0.160.8 \cdot 0.2 = 0.16 and 0.2⋅0.8=0.160.2 \cdot 0.8 = 0.16, so P(A)=0.32P(A) = 0.32 and P(F∣A)=1/2P(F \mid A) = 1/2. The review time per alerted item becomes 7.57.5 minutes, and per item it becomes 12⋅0.16+3⋅0.16=2.412 \cdot 0.16 + 3 \cdot 0.16 = 2.4 minutes. The inspection itself did not change, yet the meaning of an alert did, because the base rate did.

A change of assumption can matter as much as a change of input. Keep P(F)=0.1P(F) = 0.1, but suppose instead, as an extreme case of dependence, that ten items always share one alert outcome, so I1=⋯=I10I_1 = \dots = I_{10}. Each item still has alert probability 0.260.26, so E[N]=2.6E[N] = 2.6 by linearity. But now the count is either 00 or 1010, the probability of at least one alert is 0.260.26 instead of about 0.9510.951, and the variance is 100⋅0.26⋅0.74=19.24100 \cdot 0.26 \cdot 0.74 = 19.24 instead of 1.9241.924.

Prediction versus simulated output

Definition A prediction is a number derived exactly from the model, such as P(A)=0.26P(A) = 0.26 or the standard error of a planned estimate. A simulated output is the recorded result of one run of a program that generates outcomes from the model. It is one realization of a random quantity whose distribution the model predicts. If an event has model probability pp, the fraction p^n\hat{p}_n of nn independent simulated trials in which it occurs has mean pp and standard error

SE⁡(p^n)=p(1−p)n.\operatorname{SE}(\hat{p}_n) = \sqrt{\frac{p(1 - p)}{n}} .

An empirical observation, such as a count from a real inspection line, is a third kind of evidence. Agreement between a simulation and the prediction supports the program, not the claim that the inputs describe a real system.

In plain words Exact arithmetic already answers this model’s questions, so here a simulation serves as a check that a program builds the model correctly. A simulated output usually lands within a few standard errors of the prediction, and a much larger gap points to an error in the program or in the calculation. No number of simulated items replaces evidence about real fault and alert rates.

Example A faithful program draws each item’s fault status first and then its alert with probability 0.80.8 or 0.20.2 according to that status. A program that gives every item alert probability 0.260.26 regardless of its fault status matches P(A)P(A) but makes fault and alert independent, so its fraction of faults among alerts estimates 0.10.1 instead of 4/134/13. For this page the faithful protocol was run once for 10,000 items in Python 3.12 with the generator random.Random(20261013). An item was faulty when its first random() draw was below 0.10.1, and it raised an alert when its second draw was below 0.80.8 or 0.20.2 according to its fault status. The run recorded 2570 alerts, 832 of them on faulty items, and 15,198 review minutes.

QuantityPredictionSimulated outputStandard error
Alert fraction0.260.260.25700.25700.00440.0044
Faults among alerts0.30770.30770.32370.3237about 0.00910.0091
Review minutes per item1.51.51.51981.51980.0330.033

The first standard error is 0.26⋅0.74/10000≈0.0044\sqrt{0.26 \cdot 0.74/10000} \approx 0.0044. For review minutes, E[R2]=144⋅0.08+9⋅0.18=13.14E[R^{2}] = 144 \cdot 0.08 + 9 \cdot 0.18 = 13.14, so Var⁡(R)=13.14−1.52=10.89\operatorname{Var}(R) = 13.14 - 1.5^{2} = 10.89, SD⁡(R)=3.3\operatorname{SD}(R) = 3.3 and the standard error is 3.3/100=0.0333.3/100 = 0.033. The standard error for faults among alerts is computed given the 2570 alerts, among which each item is faulty independently with probability 4/134/13, so it is (4/13)(9/13)/2570≈0.0091\sqrt{(4/13)(9/13)/2570} \approx 0.0091. All three outputs lie within two standard errors of their predictions. The conditional fraction rests on only 2570 alerted items, so its standard error is about twice that of the alert fraction. The lesson Simulation Error and Number of Trials develops these standard errors.

Check yourself

  1. In the original model, find the probability that an item without an alert is faulty. Why is the answer neither 0.20.2 nor 0.020.02?
Show the answer

The no-alert column of the joint table holds 0.020.02 for faulty items and 0.720.72 for nonfaulty ones, so P(Ac)=0.74P(A^{c}) = 0.74 and

P(F∣Ac)=0.020.74=137,P(F \mid A^{c}) = \frac{0.02}{0.74} = \frac{1}{37},

about 0.0270.027. The number 0.20.2 is P(Ac∣F)=1−0.8P(A^{c} \mid F) = 1 - 0.8, the chance that a faulty item raises no alert, which conditions in the other direction. The number 0.020.02 is the joint probability P(F∩Ac)P(F \cap A^{c}), which has not yet been divided by P(Ac)P(A^{c}). A missing alert lowers the fault probability from 0.10.1 to about 0.0270.027, but not to zero.

  1. Ten independent items are inspected under the original model. Find the expected number of faulty items that raise an alert and the probability that none of the ten needs a review. Which of the two answers stays valid if the items are dependent but each still follows the one-item model?
Show the answer

Each item is a faulty alerted item with probability P(F∩A)=0.08P(F \cap A) = 0.08, so the expected number of such items is 10⋅0.08=0.810 \cdot 0.08 = 0.8. No review is needed exactly when there are no alerts, and with independent items

P(N=0)=0.7410≈0.0492.\begin{aligned} P(N = 0) &= 0.74^{10} \\[0.4em] &\approx 0.0492 . \end{aligned}

The expected value 0.80.8 comes from linearity of expectation, which needs only the probability 0.080.08 for each item, so it stays valid under dependence. The value 0.04920.0492 multiplies ten probabilities, which uses independence. In the extreme case where all ten items share one alert outcome, the probability that no review is needed is 0.740.74 instead.

  1. Keep P(F)=0.1P(F) = 0.1 and P(A∣F)=0.8P(A \mid F) = 0.8, but improve the inspection so that P(A∣Fc)=0.1P(A \mid F^{c}) = 0.1. Find P(A)P(A), P(F∣A)P(F \mid A), the expected review time per alerted item and per item, and the expected review work for ten items. Why does the review time per alert rise while the expected work falls?
Show the answer

The faulty alert cell stays 0.080.08 and the nonfaulty alert cell becomes 0.1⋅0.9=0.090.1 \cdot 0.9 = 0.09, so P(A)=0.17P(A) = 0.17 and

P(F∣A)=0.080.17=817,P(F \mid A) = \frac{0.08}{0.17} = \frac{8}{17},

about 0.47060.4706. Per alerted item,

E[R∣A]=12⋅817+3⋅917=12317≈7.235\begin{aligned} E[R \mid A] &= 12 \cdot \frac{8}{17} + 3 \cdot \frac{9}{17} \\[0.4em] &= \frac{123}{17} \approx 7.235 \end{aligned}

minutes, up from about 5.7695.769. Per item, E[R]=12⋅0.08+3⋅0.09=1.23E[R] = 12 \cdot 0.08 + 3 \cdot 0.09 = 1.23 minutes, down from 1.51.5, so ten items need 12.312.3 minutes of review on average instead of 1515. There is no contradiction. The change halves the probability of a false alert, from 0.180.18 to 0.090.09, and false alerts were the short reviews. Alerts become less frequent overall, and a larger share of them are faults with long reviews. The two averages use different groups, alerted items and all items.

How this lesson connects