Probability and Conditional Probability
A detector that recognizes most real variants can still produce many false calls when variants are rare. Conditional probability explains the difference between detecting a variant and trusting a positive call.
Read sets and combinations first. Every probability below belongs to an invented detector and an invented population of candidate sites.
Events and their probabilities
Section titled “Events and their probabilities”An event is a set of outcomes. Let V mean that a candidate site contains a real variant, and let + mean that the detector reports a positive result. A probability lies between zero and one. The complement of an event has probability one minus the event’s probability.
The joint probability P(V and +) describes both events occurring. The conditional probability P(+ | V) describes a positive result among real variants. The vertical bar means “given.”
Conditional probability follows P(A | B) = P(A and B) / P(B) when P(B) is positive. Therefore, P(A and B) = P(A | B)*P(B).
Start with expected counts
Section titled “Start with expected counts”Use a detector with sensitivity 0.95 and a false positive rate of 0.02. Suppose the prevalence of real variants among candidate sites is 0.01.
candidate_count = 10000prevalence = 0.01sensitivity = 0.95false_positive_rate = 0.02true_positive = candidate_count * prevalence * sensitivityfalse_positive = ( candidate_count * (1.0 - prevalence) * false_positive_rate)positive_predictive_value = true_positive / (true_positive + false_positive)print(f"Expected true positives: {true_positive:.1f}")print(f"Expected false positives: {false_positive:.1f}")print(f"P(variant | positive): {positive_predictive_value:.4f}")Expected true positives: 95.0Expected false positives: 198.0P(variant | positive): 0.3242These are expected counts under the model, not observations from a detector validation study. The nonvariant sites are numerous enough to contribute many false positives despite the small false positive rate.
Bayes’ rule reverses the condition
Section titled “Bayes’ rule reverses the condition”Arrange the expected counts by both the detector’s call and the site’s true state. The table makes the population behind each probability explicit.
true_negative = candidate_count * (1.0 - prevalence) * ( 1.0 - false_positive_rate)false_negative = candidate_count * prevalence * (1.0 - sensitivity)print(f"{'Call':<12} {'Variant':>10} {'No variant':>12} {'Total':>10}")print(f"{'Positive':<12} {true_positive:10.0f} {false_positive:12.0f} " f"{true_positive + false_positive:10.0f}")print(f"{'Negative':<12} {false_negative:10.0f} {true_negative:12.0f} " f"{false_negative + true_negative:10.0f}")print(f"{'Total':<12} {true_positive + false_negative:10.0f} " f"{false_positive + true_negative:12.0f} {candidate_count:10.0f}")Call Variant No variant TotalPositive 95 198 293Negative 5 9702 9707Total 100 9900 10000To calculate sensitivity, stay within the variant column and ask which sites have a positive call. To calculate positive predictive value, stay within the positive row and ask which sites contain a variant. The numerator is the same cell, but the denominator changes.
A marginal probability uses a row or column total divided by the grand total. A joint probability uses one cell divided by the grand total. A conditional probability restricts the denominator to the relevant row or column. Identifying that denominator before inserting numbers prevents a reversal of the condition.
The total probability of a positive call is the sum of positives from real variants and nonvariants.
P(+) = P(+ | V)*P(V) + P(+ | not V)*P(not V)P(V | +) = P(+ | V)*P(V) / P(+)The first line partitions the candidate sites into two mutually exclusive groups. The second line is Bayes’ rule. Sensitivity and positive predictive value condition on different populations.
for prior in [0.001, 0.01, 0.1]: positive_probability = ( sensitivity * prior + false_positive_rate * (1.0 - prior) ) posterior = sensitivity * prior / positive_probability print(f"Prevalence {prior:.3f}: P(variant | positive) {posterior:.4f}")Prevalence 0.001: P(variant | positive) 0.0454Prevalence 0.010: P(variant | positive) 0.3242Prevalence 0.100: P(variant | positive) 0.8407This comparison holds the detector’s conditional performance fixed. In practice, a different candidate population can also change sensitivity and the false positive rate.
The Bayes’ theorem tutorial applies the same calculation to a diagnostic test. Its expected count table distinguishes sensitivity, specificity, overall accuracy, and positive predictive value.
Independence is an assumption
Section titled “Independence is an assumption”Two events are independent when P(A and B) = P(A)*P(B). Equivalently, knowing one event does not change the probability of the other, when the conditional probabilities exist.
For independent reads with a common error probability, the probability that every read is correct is a product. Its complement is the probability of at least one error.
error_probability = 0.01read_count = 20all_correct = (1.0 - error_probability) ** read_countprint(f"P(at least one error): {1.0 - all_correct:.4f}")P(at least one error): 0.1821PCR duplicates and systematic sequencing artifacts can violate independence. A product of probabilities does not establish that the observations are independent.
Check your understanding
Section titled “Check your understanding”If the false positive rate decreases while prevalence and sensitivity stay fixed, what happens to positive predictive value?
The expected true positive count stays fixed while the expected false positive count decreases. True positives therefore form a larger share of positive calls. This conclusion follows from the denominator, without needing to memorize another formula.
Further reading
Section titled “Further reading”-
MIT Introduction to Probability and Statistics
The course covers conditional probability, independence, and Bayesian inference. Its problems provide further practice with the denominators in the detector example.
Continue with random variables and distributions. The ROC guide applies related quantities to classifier scores.