Skip to content

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.

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).

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 = 10000
prevalence = 0.01
sensitivity = 0.95
false_positive_rate = 0.02
true_positive = candidate_count * prevalence * sensitivity
false_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.0
Expected false positives: 198.0
P(variant | positive): 0.3242

These 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.

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 Total
Positive 95 198 293
Negative 5 9702 9707
Total 100 9900 10000

To 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.0454
Prevalence 0.010: P(variant | positive) 0.3242
Prevalence 0.100: P(variant | positive) 0.8407

This 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.

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.01
read_count = 20
all_correct = (1.0 - error_probability) ** read_count
print(f"P(at least one error): {1.0 - all_correct:.4f}")
P(at least one error): 0.1821

PCR duplicates and systematic sequencing artifacts can violate independence. A product of probabilities does not establish that the observations are independent.

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.

Continue with random variables and distributions. The ROC guide applies related quantities to classifier scores.