Probability Basics

  • Sample space = all possible outcomes of an experiment.
  • Event = a subset of outcomes.
  • Probability of an event \(A\): \(0 \leq P(A) \leq 1\).
  • The complement of an event \(A\), written as \(A^c\), is the event that \(A\) does not happen, such as \(P(A^c) = 1 - P(A)\).
  • Probability of the union of two events, \(A\) and \(B\) is \(P(A \cup B) = P(A)+ P(B) - P(A \cap B)\).

Example 1: Coin Flips

  • One fair coin flip: \(P(Heads) = \frac{1}{2}\).

  • For an experiment with two flips, the sample space is \(4\).

  • Example: If event \(A\) is “exactly one head”, \(P(A) = \frac{2}{4} = \frac{1}{2}\).

Example 1: Code

set.seed(2025)
n <- 2000
flips <- sample(c("H", "T"), size = n, replace = TRUE)

coin_df <- data.frame(flip = flips) |>
  group_by(flip) |>
  summarize(count = n(), .groups = "drop") |>
  mutate(prop = count / sum(count))

Example 1: Code For Visualization

ggplot(coin_df, aes(x = flip, y = prop, fill = flip)) +
  geom_col() +
  scale_fill_manual(values = c("H" = "yellow2", "T" = "pink3")) +
  labs(
    title = "Coin Flip Proportions (Simulation, n = 2000)",
    x = "Outcome",
    y = "Proportion"
  ) +
  theme_minimal()

Example 1: Visualization

Example 2: Dice Sums

  • Roll two fair six-sided dice.

  • Each dies: has a value of either \({1, 2, 3, 4, 5, 6}\).

  • Total sample space: \(6\).

  • The range of sum values is any integer between \(2\) and \(12\).

Example 2: Code

dice <- expand.grid(d1 = 1:6, d2 = 1:6)
dice$sum <- dice$d1 + dice$d2




sum_counts <- dice |>
group_by(sum) |>
summarize(count = n(), .groups = "drop") |>
mutate(prob = count / sum(count))

Example 2: Visualization

Example 2: Interactive 3D Plot

Example 3: Books

  • J is taking two books on holiday. \(P(B_1)=0.5\) (likes book 1), \(P(B_2)=0.4\) (likes book 2), and \(P(B_1 \cap B_2)=0.3\) (likes both).
  • The probability she likes neither book can be found given the probability she likes at least one. \[P(B_1 \cup B_2) = P(B_1) + P(B_2) - P(B_1 \cap B_2) = 0.5 + 0.4 - 0.3 = 0.6\]
  • Thus the probability she likes neither, which is the complement of \(P(B_1 \cup B_2)\) is \(P(B_1^c \cap B_2^c) = 1 - P(B_1 \cup B_2) \to P(B_1^c \cap B_2^c) = 1 - 0.6 = 0.4\).