Book contents

STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 4

Probability Basics

Probability theory provides the language for quantifying uncertainty. Before we can perform statistical inference, we must understand how to define events, assign probabilities and manipulate them according to precise rules.

Sample Spaces and Events

Probability is a function PP that assigns a number between 0 and 1 to each event, satisfying:

If all outcomes in Ω\Omega are equally likely and there are nn outcomes in event AA, then P(A)=n/|Ω|P(A) = n / |\Omega|. For example, the probability of rolling an even number on a fair six-sided die is 3/6=1/23/6 = 1/2.

Union, Intersection and Complement

The union of events AA and BB is the event that at least one occurs: A∪B={ω:ω∈A or ω∈B}A \cup B = \{ \omega: \omega \in A \text{ or } \omega \in B \}. The intersection A∩BA \cap B is the event that both occur. The probability of the union is given by P(A∪B)=P(A)+P(B)−P(A∩B).P(A \cup B) = P(A) + P(B) - P(A \cap B).

The complement of AA, denoted AcA^c, is the event that AA does not occur. We have P(Ac)=1−P(A)P(A^c) = 1 - P(A).

Conditional Probability

The probability of AA given BB is P(A∣B)=P(A∩B)P(B),P(B)>0.P(A \mid B) = \frac{P(A \cap B)}{P(B)}, \quad P(B) > 0. Conditional probabilities allow us to update beliefs in light of new information. Two events AA and BB are independent if P(A∩B)=P(A)P(B)P(A \cap B) = P(A) P(B); equivalently, P(A∣B)=P(A)P(A \mid B) = P(A).

Law of Total Probability and Bayes’ Theorem

If B1,B2,…,BkB_1, B_2, \dots, B_k partition the sample space (i.e., are disjoint events whose union is Ω\Omega), then for any event AA, P(A)=∑i=1kP(A∣Bi)P(Bi).P(A) = \sum_{i=1}^k P(A \mid B_i) P(B_i).

Bayes’ theorem reverses conditioning: P(Bj∣A)=P(A∣Bj)P(Bj)∑i=1kP(A∣Bi)P(Bi).P(B_j \mid A) = \frac{P(A \mid B_j) P(B_j)}{\sum_{i=1}^k P(A \mid B_i) P(B_i)}.

Bayes’ theorem underlies diagnostic testing. The sensitivity (true positive rate) and specificity (true negative rate) of a test, combined with disease prevalence, determine the positive predictive value (probability of disease given a positive test).

Worked example

Diagnostic Test Example.

Suppose a disease has prevalence 1%. A test has sensitivity 95% and specificity 90%. What is the probability that a person who tests positive actually has the disease?

Using Bayes’ theorem with DD denoting disease and TT a positive test result: P(D∣T)=P(T∣D)P(D)P(T∣D)P(D)+P(T∣Dc)P(Dc)=0.95×0.010.95×0.01+0.10×0.99≈0.087.P(D \mid T) = \frac{P(T \mid D) P(D)}{P(T \mid D)P(D) + P(T \mid D^c)P(D^c)} = \frac{0.95 \times 0.01}{0.95 \times 0.01 + 0.10 \times 0.99} \approx 0.087.

Thus, fewer than 10% of positive results are true positives. The low prevalence overwhelms the high sensitivity, demonstrating the importance of context in interpreting test results.

Simulating Probabilities

Simulation helps build intuition. By simulating many replications of a random process, we can approximate probabilities empirically.

Simulating coin flips in Python:

import numpy as np

# Simulate 10000 fair coin flips (1 for heads, 0 for tails)
n_flips = 10000
flips = np.random.randint(0, 2, size=n_flips)

prob_heads = np.mean(flips)
print(prob_heads)  # Approximate probability of heads

Simulating a dice roll in R:

set.seed(42)
rolls <- sample(1:6, 10000, replace=TRUE)
prob_six <- mean(rolls == 6)

Exercises

Practice

  1. A deck contains 52 cards. What is the probability of drawing an ace or a king? What is the probability of drawing an ace given that the card is a heart?

  2. Two fair six-sided dice are rolled. What is the probability the sum is 7? What is the probability that at least one die shows a 6? Are the events “sum is 7” and “at least one 6” independent?

  3. In an industrial process, the probability that a part is defective is 2%. Two inspectors independently check each part. Each inspector misses 10% of defects. Calculate the probability that a defective part is accepted (both inspectors miss it). What is the probability that a part accepted by both inspectors is actually defective?

  4. Write code in Python, R or Julia to simulate rolling a pair of dice 10 000 times. Estimate the probability that the sum is divisible by 3. Compare to the exact probability computed by enumeration.

References