Mehmet Emre Tiryaki
Back to Notes

Random Variables and Distributions

Random Variables and Distributions

A random variable XX is a map from the sample space Ω\Omega to a set SS.

E.g. let XX be the RV that counts the number of heads for 2 coin flips. Then Ω={HH,HT,TH,TT}\Omega = \{HH, HT, TH, TT\} and S={0,1,2}S = \{0, 1, 2\}.

A distribution of a random variable is a mapping from events (certain subset combinations of Ω\Omega, this is a very non-rigorous definition) to [0,1][0,1]. E.g. for the example above the distribution is the collection of probabilities P(X=x)P(X = x) for x∈Sx \in S,

P(X=0)=P({TT})=14P(X=1)=P({HT,TH})=12P(X=2)=P({HH})=14\begin{aligned} P(X = 0) &= P(\{TT\}) = \tfrac{1}{4} \\ P(X = 1) &= P(\{HT, TH\}) = \tfrac{1}{2} \\ P(X = 2) &= P(\{HH\}) = \tfrac{1}{4} \end{aligned}

For discrete cases the distribution is given via the probability mass function (PMF),

pX(x)=P(X=x),x∈Sp_X(x) = P(X = x), \quad x \in S

remember XX is the RV, xx is a given value.

For continuous distributions we give the distribution with the probability density function (pdf), pX(x)p_X(x) or fX(x)f_X(x), defined by

P(a≤X≤b)=∫abpX(x) dxand∫RpX(x) dx=1P(a \le X \le b) = \int_a^b p_X(x) \, dx \quad \text{and} \quad \int_{\mathbb{R}} p_X(x) \, dx = 1

The cumulative distribution function (CDF) is

FX(x)=P(X≤x)F_X(x) = P(X \le x)

So for any RV, P(X=x)P(X = x) or P(x1≤X≤x2)P(x_1 \le X \le x_2) is a specific case, not the distribution itself. The distribution is defined through a PMF pX(x)p_X(x) (discrete) or a CDF FX(x)F_X(x) (all RVs), which may define a pdf pX(x)p_X(x) (continuous).

We denote the distribution of an RV with the ∼\sim notation, i.e. X∼D(θ)X \sim D(\theta) means XX is distributed with DD using parameters θ\theta. E.g. X∼N(0,1)X \sim \mathcal{N}(0,1) means XX is normally distributed with mean 0 and variance 1.

Joint Distributions

A joint distribution is the distribution induced by multiple RVs together. E.g. remember the distribution of XX defined P(X=x)P(X = x) for all x∈{0,1,2}x \in \{0,1,2\}. Now let YY be the RV that is 1 if the first flip is heads, 0 otherwise. Then the joint distribution of X,YX, Y is

P(X=0,Y=0)=P({TT})=14P(X=0,Y=1)=P(∅)=0P(X=1,Y=0)=P({TH})=14P(X=1,Y=1)=P({HT})=14P(X=2,Y=0)=P(∅)=0P(X=2,Y=1)=P({HH})=14\begin{aligned} P(X = 0, Y = 0) &= P(\{TT\}) = \tfrac{1}{4} & P(X = 0, Y = 1) &= P(\varnothing) = 0 \\ P(X = 1, Y = 0) &= P(\{TH\}) = \tfrac{1}{4} & P(X = 1, Y = 1) &= P(\{HT\}) = \tfrac{1}{4} \\ P(X = 2, Y = 0) &= P(\varnothing) = 0 & P(X = 2, Y = 1) &= P(\{HH\}) = \tfrac{1}{4} \end{aligned}

The pdf or pmf of the joint distribution of 2 RVs XX and YY is denoted pX,Y(x,y)p_{X,Y}(x,y), or simply p(x,y)p(x,y). If discrete, pX,Y(x,y)=P(X=x,Y=y)p_{X,Y}(x,y) = P(X = x, Y = y).

A marginal distribution is the distribution of only one RV in the context of a joint. E.g. pX(x),pY(y)p_X(x), p_Y(y) are the marginals of XX and YY, pX,Y(x,y)p_{X,Y}(x,y) is the joint distribution.

For any joint distribution, we can recover a marginal by integrating the other out,

pX(x)=∫pX,Y(x,y) dy,collapses topX(x)=∑ypX,Y(x,y) in discretep_X(x) = \int p_{X,Y}(x,y) \, dy, \qquad \text{collapses to} \qquad p_X(x) = \sum_{y} p_{X,Y}(x,y) \text{ in discrete}

If the joint distribution factorizes, the RVs are independent (marginally independent). If pX,Y(x,y)=pX(x) pY(y)p_{X,Y}(x,y) = p_X(x)\, p_Y(y) then XX and YY are independent, and vice versa. Also denoted X⊥ ⁣ ⁣ ⁣⊥YX \perp\!\!\!\perp Y.

Conditional Distributions

A conditional distribution is the distribution of one or multiple RVs conditioned on some other RVs. E.g. from the last example, in the conditional distribution of X∣YX | Y,

P(X=0∣Y=0)=12P(X = 0 \mid Y = 0) = \tfrac{1}{2}

as Y=0Y = 0 means XX can only be 0 or 1 with equal probability.

pX∣Y(x∣y)p_{X|Y}(x|y), or p(x∣y)p(x|y), is used to denote the pdf or pmf of the conditional distribution. Again p(x∣Y=i)p(x | Y = i) is conditioning on a specific realization of YY, while p(x∣y)p(x|y) is the whole conditional distribution.

p(x∣y)=p(x,y)p(y)p(x|y) = \frac{p(x,y)}{p(y)}

If XX and YY are independent, p(x∣y)=p(x)p(x|y) = p(x), as information on YY doesn't give any information on XX.

Note that abuse of notation is very common and not necessarily incorrect. For example, let DD be a random variable with D=1D = 1 if someone has a disease and 0 if not. Then P(Sick)=P(D=1)P(\text{Sick}) = P(D = 1) would be an OK understanding without need for such a definition.

Law of Total Probability

The law of total probability states the probability of an event is the total probability of its different cases. For an event AA,

p(A)=∫p(A∣Y=y) p(y) dyor∑yp(A∣Y=y) P(Y=y)p(A) = \int p(A | Y = y)\, p(y) \, dy \quad \text{or} \quad \sum_{y} p(A | Y = y)\, P(Y = y)

E.g. from the example,

P(X=2)=P(X=2∣Y=0)P(Y=0)+P(X=2∣Y=1)P(Y=1)=0+12⋅12=14P(X = 2) = P(X = 2 | Y = 0)P(Y = 0) + P(X = 2 | Y = 1)P(Y = 1) = 0 + \tfrac{1}{2} \cdot \tfrac{1}{2} = \tfrac{1}{4}

Conditional Independence

RVs XX and YY are conditionally independent given an RV ZZ if

  1. P(X∣Y,Z)=P(X∣Z)P(X | Y, Z) = P(X | Z),
  2. P(Y∣X,Z)=P(Y∣Z)P(Y | X, Z) = P(Y | Z),
  3. P(X,Y∣Z)=P(X∣Z)⋅P(Y∣Z)P(X, Y | Z) = P(X | Z) \cdot P(Y | Z).

1 and 2 say knowledge of the other RV doesn't matter given ZZ, 3 says the joint distribution factorizes given ZZ. Also denoted X⊥ ⁣ ⁣ ⁣⊥Y∣ZX \perp\!\!\!\perp Y \mid Z.

This generalizes to more RVs, e.g.

X1,X2,X3⊥ ⁣ ⁣ ⁣⊥Y1,Y2∣Z1,Z2  ⟹  P(X1,X2,X3,Y1,Y2∣Z1,Z2)=P(X1,X2,X3∣Z1,Z2) P(Y1,Y2∣Z1,Z2)X_1, X_2, X_3 \perp\!\!\!\perp Y_1, Y_2 \mid Z_1, Z_2 \implies P(X_1, X_2, X_3, Y_1, Y_2 | Z_1, Z_2) = P(X_1, X_2, X_3 | Z_1, Z_2)\, P(Y_1, Y_2 | Z_1, Z_2)

Semi-graphoid axioms For sets of RVs X,Y,Z,WX, Y, Z, W,

  1. X⊥ ⁣ ⁣ ⁣⊥Y∣Z  ⟺  Y⊥ ⁣ ⁣ ⁣⊥X∣ZX \perp\!\!\!\perp Y \mid Z \iff Y \perp\!\!\!\perp X \mid Z,
  2. X⊥ ⁣ ⁣ ⁣⊥Y∪W∣Z  ⟺  X⊥ ⁣ ⁣ ⁣⊥W∣ZX \perp\!\!\!\perp Y \cup W \mid Z \iff X \perp\!\!\!\perp W \mid Z and X⊥ ⁣ ⁣ ⁣⊥Y∣Z∪WX \perp\!\!\!\perp Y \mid Z \cup W.

Bayes' Rule and Chain Rule

Bayes' Rule For RVs A,BA, B,

P(A∣B)=P(B∣A) P(A)P(B)P(A | B) = \frac{P(B | A)\, P(A)}{P(B)}

Chain Rule For RVs X1,…,XnX_1, \ldots, X_n,

P(X1,…,Xn)=∏i=1nP(Xi∣Xi−1,…,X1)P(X_1, \ldots, X_n) = \prod_{i=1}^{n} P(X_i | X_{i-1}, \ldots, X_1)