Lesson 5: Equally Likely Outcomes and Counting

Meike Niederhausen and Nicky Wakim

2026-10-12

Learning Objectives

  1. Define permutations and combinations

  2. Calculate the probability of sampling any combination of the following: with or without replacement and order does or does not matter

  3. Use a simulation to check a probability found by counting

Where are we?

Birthday example

Basic Counting Examples (1/3)

Example 1

Suppose we have 10 (distinguishable) subjects for study.

  1. How many possible ways are there to order them?

  2. How many ways to order them if we can reuse the same subject and

    • need 10 total?

    • need 6 total?

  3. How many ways to order them without replacement and only need 6?

  4. How many ways to choose 6 subjects without replacement if the order doesn’t matter?

Basic Counting Examples (2/3)

Suppose we have 10 (distinguishable) subjects for study.

Example 1.1

How many possible ways are there to order them?

 

Example 1.2

How many ways to order them if we can reuse the same subject and

  • need 10 total?

  • need 6 total?

Basic Counting Examples (3/3)

Suppose we have 10 (distinguishable) subjects for study.

Example 1.3

How many ways to order them without replacement and only need 6?

 

Example 1.4

How many ways to choose 6 subjects without replacement if the order doesn’t matter?

Learning Objectives

  1. Define permutations and combinations
  1. Calculate the probability of sampling any combination of the following: with or without replacement and order does or does not matter

  2. Use a simulation to check a probability found by counting

Permutations and Combinations

Definition: Permutations

Permutations are the number of ways to arrange in order \(r\) distinct objects when there are \(n\) total.

\[nPr = \frac{n!}{(n-r)!}\]

Definition: Combinations

Combinations are the number of ways to choose (order doesn’t matter) \(r\) objects from \(n\) without replacement.

\[nCr = \textrm{"n choose r"} = \binom{n}{r} = \frac{n!}{r!(n-r)!}\]

  • We will see combinations a lot in the binomial distribution

Some combinations properties

Property Proof
\[\binom{n}{r} = \binom{n}{n-r}\] \(\binom{n}{r} = \dfrac{n!}{r!(n-r)!}\) and \(\binom{n}{n-r} = \dfrac{n!}{(n-r)!(n-(n-r))!} = \dfrac{n!}{(n-r)!r!}\)
\[\binom{n}{1} = n\] \[\binom{n}{1} = \dfrac{n!}{1!(n-1)!}=\dfrac{n\cdot(n-1)\cdot(n-2)\cdots1}{1! \cdot (n-1)\cdot(n-2)\cdots1} = \dfrac{n\cdot(n-1)!}{1\cdot (n-1)!} = \dfrac{n}{1}=n\]
\[\binom{n}{0} = 1\] \[\binom{n}{0} = \dfrac{n!}{0!(n-0)!}=\dfrac{n!}{1\cdot n!} = 1\]

Learning Objectives

  1. Define permutations and combinations
  1. Calculate the probability of sampling any combination of the following: with or without replacement and order does or does not matter
  1. Use a simulation to check a probability found by counting

Table of different cases

  • \(n\) = total number of objects

  • \(r\) = number objects needed

    with replacement without replacement
    order matters \[n^r\] \[n\text{P}r = \frac{n!}{(n-r)!}\] (permutations)
    order doesn’t matter \[ \binom{n+r-1}{r}\] \[n\text{C}r = \binom{n}{r} = \frac{n!}{r!(n-r)!}\] (combinations)

Enumerating Events and Sample Space

  • Recall, \(P(A) = \dfrac{|A|}{|S|}\)
    • Within combinatorics, we can use the previous equations to help enumerate the event and sample space
    • But \(A\) might be a combination of enumerations

 

  • For example in the following example drawing 2 spades when order does not matter, we actually need to enumerate the other cards that are NOT spades. So the event is choosing 2 spades out of 13 AND choosing 0 other cards of 39 cards (13 hearts + 13 clubs + 13 diamonds).

  • Thus the probability is actually:

\[ P(\text{two spades}) = \dfrac{{13 \choose 2}{39 \choose 0}}{{52 \choose 2}} \]

  • Note that \(13 + 39 = 52\) and \(2+ 0 = 2\). So the numerator’s \(n\)’s add up to the denominator’s \(n\) and the numerator’s \(r\)’s add up to the denominator’s \(r\)’s

Example 2

Suppose we draw 2 cards from a standard deck without replacement. What is the probability that both are spades when

  1. order matters?
  2. order doesn’t matter?

Example 2

Suppose we draw 2 cards from a standard deck without replacement. What is the probability that both are spades when

  1. order matters?
  2. order doesn’t matter?

We can do a simulation! First, a tiny version with 5 simulations:

set.seed(1234)
suits <- c("S", "H", "C", "D")
deck <- rep(suits, each = 13)

reps <- 5
hands <- expand_grid(sim = 1:reps, draw = 1:2) |>
  group_by(sim) |>
  mutate(card = sample(deck, n(), replace = FALSE)) |>
  ungroup()
hands
1
Set the seed once, so everyone gets the same random draws.
2
The four suits: spades (S), hearts (H), clubs (C), diamonds (D).
3
rep() repeats each suit 13 times (each = 13), so deck holds all 52 cards.
4
Save the number of simulations as reps, so it is easy to change later.
5
Make a table with one row for each card drawn: two draws for every simulation. The pipe |> passes it to the next line.
6
Do the next step separately within each simulation.
7
mutate() adds a column called card. For each simulation, sample() picks 2 cards from the deck. replace = FALSE means a card cannot be picked twice.
8
ungroup() turns the grouping off, so later steps use the whole table.
# A tibble: 10 × 3
     sim  draw card 
   <int> <int> <chr>
 1     1     1 C    
 2     1     2 H    
 3     2     1 H    
 4     2     2 C    
 5     3     1 D    
 6     3     2 D    
 7     4     1 S    
 8     4     2 S    
 9     5     1 C    
10     5     2 H    

Example 2

Suppose we draw 2 cards from a standard deck without replacement. What is the probability that both are spades when

  1. order matters?
  2. order doesn’t matter?

Same code, now with 100,000 simulations. Then check each simulated hand:

set.seed(1234)
reps <- 100000
hands <- expand_grid(sim = 1:reps, draw = 1:2) |>
  group_by(sim) |>
  mutate(card = sample(deck, n(), replace = FALSE)) |>
  ungroup()

spade_results <- hands |>
  group_by(sim) |>
  summarise(ordered = card[1] == "S" & card[2] == "S",
            unordered = sum(card == "S") == 2)

spade_results |>
  summarise(prob_ordered = mean(ordered),
            prob_unordered = mean(unordered))
1
The only change: 100,000 simulations instead of 5.
2
Look at one simulated hand at a time.
3
Order matters: TRUE if the first card is a spade and the second card is a spade. [1] and [2] pick the first and second card.
4
Order doesn’t matter: TRUE if exactly 2 of the 2 cards are spades. sum() counts the TRUEs.
5
mean() of a TRUE/FALSE column is the proportion of TRUEs, because TRUE counts as 1 and FALSE as 0.
# A tibble: 1 × 2
  prob_ordered prob_unordered
         <dbl>          <dbl>
1       0.0588         0.0588

Exact answer: choose(13, 2) / choose(52, 2) = 0.0588

Learning Objectives

  1. Define permutations and combinations

  2. Calculate the probability of sampling any combination of the following: with or without replacement and order does or does not matter

  1. Use a simulation to check a probability found by counting

Birthday paradox revisited (1/3)

Example 3

Suppose 8 people are in a room, and every day of the year is equally likely to be a birthday (ignore leap days). What is the probability that at least two people share a birthday?

 

set.seed(550)
reps <- 100000
n_people <- 8
birthdays <- expand_grid(sim = 1:reps, person = 1:n_people) |>
  mutate(birthday = sample(1:365, n(), replace = TRUE))
head(birthdays, 10)
1
Set the seed so the results can be reproduced.
2
The number of simulated rooms.
3
The number of people in each room.
4
One row for each person in each simulated room.
5
Each person gets a random day from 1 to 365. replace = TRUE because two people can share a birthday.
# A tibble: 10 × 3
     sim person birthday
   <int>  <int>    <int>
 1     1      1      145
 2     1      2      246
 3     1      3      284
 4     1      4       90
 5     1      5       75
 6     1      6      293
 7     1      7      164
 8     1      8      266
 9     2      1      124
10     2      2       60

Birthday paradox revisited (2/3)

room_results <- birthdays |>
  group_by(sim) |>
  summarise(n_different = n_distinct(birthday)) |>
  mutate(shared = n_different < n_people)

room_results |>
  summarise(prob_shared = mean(shared))
1
Look at one simulated room at a time.
2
n_distinct() counts how many different birthdays are in the room.
3
If fewer than 23 different birthdays, at least two people share one. shared is TRUE or FALSE.
4
mean() gives the proportion of rooms with a shared birthday.
# A tibble: 1 × 1
  prob_shared
        <dbl>
1      0.0730

Exact answer: \[1 - \dfrac{365 \cdot 364 \cdots 343}{365^{23}} = 0.5073\]

Birthday paradox revisited (3/3)

Sensitivity analysis: what if there are 30 people in the room?

reps <- 100000
n_people <- 30
birthdays <- expand_grid(sim = 1:reps, person = 1:n_people) |>
  mutate(birthday = sample(1:365, n(), replace = TRUE))

birthdays |>
  group_by(sim) |>
  summarise(n_different = n_distinct(birthday)) |>
  mutate(shared = n_different < n_people) |>
  summarise(prob_shared = mean(shared))
1
The only change: 30 people instead of 23. The probability goes up.
# A tibble: 1 × 1
  prob_shared
        <dbl>
1       0.707

Learning Objectives

  1. Define permutations and combinations

  2. Calculate the probability of sampling any combination of the following: with or without replacement and order does or does not matter

  3. Use a simulation to check a probability found by counting