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
A sample space is the set of all possible outcomes of an experiment. For a coin toss, .
An event is a subset of the sample space. In a dice roll, is the event that the result is at most 3.
Probability is a function that assigns a number between 0 and 1 to each event, satisfying:
.
If and are disjoint events, then .
If all outcomes in are equally likely and there are outcomes in event , then . For example, the probability of rolling an even number on a fair six-sided die is .
Union, Intersection and Complement
The union of events and is the event that at least one occurs: . The intersection is the event that both occur. The probability of the union is given by
The complement of , denoted , is the event that does not occur. We have .
Conditional Probability
The probability of given is Conditional probabilities allow us to update beliefs in light of new information. Two events and are independent if ; equivalently, .
Law of Total Probability and Bayes’ Theorem
If partition the sample space (i.e., are disjoint events whose union is ), then for any event ,
Bayes’ theorem reverses conditioning:
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 denoting disease and a positive test result:
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
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?
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?
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?
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
Ross SM. Introduction to Probability and Statistics for Engineers and Scientists. 6th ed. Academic Press; 2020.
Grinstead CM, Snell JL. Introduction to Probability. 2nd ed. American Mathematical Society; 1997.
Johnson RA, Miller I. Friend, Stewart. Probability and Statistics for Engineers. Pearson; 2020.