Statistics Combinations
A combination counts the number of ways to choose items from a group when the order of selection does not matter.
What Is a Combination?
A combination is a selection of items where order does not matter. Choosing 3 books out of 5 to pack for a trip is a combination problem, because packing book A, then B, then C ends up being the exact same trio as packing C, then A, then B — you only care which books end up in the bag, not the order you grabbed them.
The Combination Formula
The number of ways to choose r items from n, when order doesn't matter, is C(n, r) = n! / (r! (n − r)!). Combinations are related to permutations by dividing out the r! ways to order each group: C(n, r) = P(n, r) / r!, since every group of r items would otherwise be counted once for each of its possible orderings.
Example: Choosing 3 Books Out of 5
import math
n = 5 # books available
r = 3 # books chosen for the trip
combinations = math.comb(n, r)
permutations = math.perm(n, r)
print(f"C(5,3) = {combinations}") # 10
print(f"Check via nPr / r! = {permutations // math.factorial(r)}") # 10With 5 books labeled A through E, choosing 3 to pack gives exactly 10 distinct groups. Order never matters here — 'A, B, C' and 'C, A, B' describe the same trio, so both collapse into a single combination.
- ABC
- ABD
- ABE
- ACD
- ACE
- ADE
- BCD
- BCE
- BDE
- CDE
Combinations vs Permutations
Example: A Lottery — Choosing 6 Numbers From 49
import math
lottery_combinations = math.comb(49, 6)
print(f"Ways to choose 6 numbers out of 49: {lottery_combinations:,}")
# 13,983,816 — this is exactly why winning a 6/49 lottery is so unlikely!Combinations are the right tool whenever you're forming a subset rather than a sequence — picking a committee from a pool of candidates, dealing a poker hand, or choosing which toppings go on a pizza, since the final group is what matters, not the order items were added.
Exercise: Statistics Combinatorics
What is the key difference between a permutation and a combination?