Probability Basics

  • Sample space = all possible outcomes of an experiment.
  • Event = a subset of outcomes.
  • Probability of an event: \(0 \leq P(A) \leq 1\).
  • Probability of the union of two events, \(A\) and \(B\) is \(P(A \cup B) = P(A) + P(B) - P(A \cap B)\).
  • Probability of the intersection of two events, \(A\) and \(B\) is \(P(A \cap B) = P(A) + P(B) - P(A \cup 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