Computing expected values and displaying a contingency table

The expected defect production is a combined probability. We'll compute the shift defect probability multiplied by the probability based on defect type. This will allow us to compute all 12 probabilities from all combinations of shift and defect type. We can weight these with the observed numbers and compute the detailed expectation for defects.

The following code calculates expected values:

expected = {    (s, t): P_shift[s]*P_type[t]*total    for t in P_type    for s in P_shift} 

We'll create a dictionary that parallels the initial defectsCounter object. This dictionary will have a sequence of two-tuples with keys and values. The keys will be two-tuples of shift and defect type. Our dictionary ...

Get Functional Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.