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 is built from a generator expression that explicitly enumerates all combinations of keys from the P_shift and...