TExcelTAD
Home › Probability Theory › Sample Spaces and Distribution Functions

Sample Spaces and Distribution Functions

To reason exactly instead of by simulation, we need a model. For experiments with finitely or countably many outcomes, the model has two parts: the set of outcomes and a weight for each one.

The model

  • The sample space Ω\Omega is the set of all possible outcomes of the experiment.
  • A distribution function m:Ω→[0,1]m : \Omega \to [0, 1] assigns each outcome a probability, with ∑ω∈Ωm(ω)=1\sum_{\omega \in \Omega} m(\omega) = 1.
  • An event is a subset E⊆ΩE \subseteq \Omega, with probability Pr⁡[E]=∑ω∈Em(ω)\Pr[E] = \sum_{\omega \in E} m(\omega).
  • A random variable is a function X:Ω→RX : \Omega \to \mathbb{R} that assigns a number to each outcome, such as "the sum of the dice".

When all nn outcomes have weight 1/n1/n the distribution is uniform, and Pr⁡[E]=∣E∣/n\Pr[E] = \lvert E \rvert / n.

Example: the sum of two dice

The sample space is the 36 ordered pairs (a,b)(a, b), each with weight 1/361/36. The random variable X=a+bX = a + b takes values 2 to 12, but not uniformly: there are more ways to make 7 than 2. Its distribution is found by grouping outcomes.

python · try it yourself
from fractions import Fraction
from itertools import product
from collections import Counter

omega = list(product(range(1, 7), repeat=2))
m = {w: Fraction(1, 36) for w in omega}
X = Counter()
for (a, b), p in m.items():
    X[a + b] += p
for s in range(2, 13):
    print(f"P(X={s:2d}) = {str(X[s]):5s} " + "#" * int(X[s] * 36))
print("total:", sum(X.values()))
P(X= 2) = 1/36  #
P(X= 3) = 1/18  ##
P(X= 4) = 1/12  ###
P(X= 5) = 1/9   ####
P(X= 6) = 5/36  #####
P(X= 7) = 1/6   ######
P(X= 8) = 5/36  #####
P(X= 9) = 1/9   ####
P(X=10) = 1/12  ###
P(X=11) = 1/18  ##
P(X=12) = 1/36  #
total: 1

A common mistake is to take the sample space to be the 11 possible sums with equal weights. The model must reflect how the experiment actually works: the dice are distinguishable (even when they look alike), so the 36 ordered pairs are the equally likely outcomes.

Choosing the sample space

The same experiment can be described at different levels of detail. For "toss a coin 3 times, count heads", you can use the 8 sequences (uniform) or the 4 counts {0,1,2,3}\{0, 1, 2, 3\} with weights 18,38,38,18\frac{1}{8}, \frac{3}{8}, \frac{3}{8}, \frac{1}{8}. Both are correct; the first is easier to justify, the second is more compact. A good rule: start with outcomes that are equally likely by symmetry, then derive the distribution of what you care about.

Infinite discrete sample spaces

Toss a coin until the first head. The outcome is the number of tosses, Ω={1,2,3,…}\Omega = \{1, 2, 3, \ldots\}, with m(k)=(1/2)km(k) = (1/2)^k. The weights sum to 1 as a geometric series:

∑k=1∞(12)k=1/21−1/2=1\sum_{k=1}^{\infty} \left(\tfrac{1}{2}\right)^k = \frac{1/2}{1 - 1/2} = 1
python · try it yourself
import random
from collections import Counter

rng = random.Random(2)
def tosses_until_head():
    k = 1
    while rng.random() >= 0.5:
        k += 1
    return k

trials = 100_000
counts = Counter(tosses_until_head() for _ in range(trials))
for k in range(1, 7):
    print(k, round(counts[k] / trials, 4), 0.5 ** k)
print("P(even number of tosses) ~", round(sum(c for k, c in counts.items() if k % 2 == 0) / trials, 4))
1 0.5008 0.5
2 0.2485 0.25
3 0.1258 0.125
4 0.0634 0.0625
5 0.0305 0.03125
6 0.0152 0.015625
P(even number of tosses) ~ 0.3325

The exact probability of an even number of tosses is ∑j≥1(1/2)2j=1/41−1/4=13\sum_{j \ge 1} (1/2)^{2j} = \frac{1/4}{1 - 1/4} = \frac{1}{3}.

In software

Every probabilistic program has an implicit sample space: the seeds of its random generator. Probabilistic programming languages (PyMC, Stan, Pyro, NumPyro) let you write the model as code and compute distributions of random variables automatically, by exact enumeration for small discrete models and by sampling otherwise.

Exercises

Exercise 1: Three coins

Toss 3 fair coins. What is the probability of exactly 2 heads? Of at least 2?

Answer

3/83/8 and 1/21/2.

Solution

Of the 8 sequences, HHT, HTH, THH have exactly 2 heads; adding HHH gives 4 with at least 2, so 4/84/8.

Exercise 2: A loaded die

A die is loaded so that the probability of face kk is proportional to kk. Find m(k)m(k) and the probability of an even face.

Answer

m(k)=k/21m(k) = k/21; Pr⁡[even]=12/21=4/7\Pr[\text{even}] = 12/21 = 4/7.

Solution

m(k)=ckm(k) = ck with c(1+2+⋯+6)=21c=1c(1 + 2 + \cdots + 6) = 21c = 1, so c=1/21c = 1/21. Even faces: (2+4+6)/21=12/21(2 + 4 + 6)/21 = 12/21.

Exercise 3: Max of two dice (code)

Find the distribution of Y=max⁡(a,b)Y = \max(a, b) for two dice and check that Pr⁡[Y=k]=(2k−1)/36\Pr[Y = k] = (2k - 1)/36.

Answer

Pr⁡[Y=k]=136,336,536,…,1136\Pr[Y = k] = \frac{1}{36}, \frac{3}{36}, \frac{5}{36}, \ldots, \frac{11}{36} for k=1,…,6k = 1, \ldots, 6.

Solution

Pr⁡[Y≤k]=k2/36\Pr[Y \le k] = k^2/36, so Pr⁡[Y=k]=(k2−(k−1)2)/36=(2k−1)/36\Pr[Y = k] = (k^2 - (k-1)^2)/36 = (2k - 1)/36.

python · try it yourself
from fractions import Fraction
from itertools import product
from collections import Counter

Y = Counter(max(a, b) for a, b in product(range(1, 7), repeat=2))
print([Fraction(Y[k], 36) for k in range(1, 7)])
print(all(Y[k] == 2 * k - 1 for k in range(1, 7)))
[Fraction(1, 36), Fraction(1, 12), Fraction(5, 36), Fraction(7, 36), Fraction(1, 4), Fraction(11, 36)]
True

Test yourself

Which condition must a distribution function mm on a discrete sample space satisfy?

  1. m(ω)=1/∣Ω∣m(\omega) = 1/|\Omega|
  2. m(ω)≥0m(\omega) \ge 0 and the weights sum to 1
  3. mm is increasing
  4. m(ω)≤1/2m(\omega) \le 1/2

What is P(sum=2)P(\text{sum} = 2) for two fair dice?

  1. 1/11
  2. 1/36
  3. 1/18
  4. 1/6