Expectation
The expectation of a random variable X X X is
E [ X ] = ∫ x p ( x ) d x , in discrete E [ X ] = ∑ x ∈ S x P ( X = x ) E[X] = \int x \, p(x) \, dx, \qquad \text{in discrete } E[X] = \sum_{x \in S} x \, P(X = x) E [ X ] = ∫ x p ( x ) d x , in discrete E [ X ] = x ∈ S ∑ x P ( X = x )
E.g. X ∼ E x p ( λ ) X \sim \mathrm{Exp}(\lambda) X ∼ Exp ( λ ) ,
E [ X ] = ∫ 0 ∞ x ⋅ λ e − λ x d x = λ ⋅ 1 λ 2 = 1 λ E[X] = \int_0^\infty x \cdot \lambda e^{-\lambda x} \, dx = \lambda \cdot \frac{1}{\lambda^2} = \frac{1}{\lambda} E [ X ] = ∫ 0 ∞ x ⋅ λ e − λ x d x = λ ⋅ λ 2 1 = λ 1
Expectation is linear ,
E [ a X + b Y ] = a E [ X ] + b E [ Y ] E[aX + bY] = aE[X] + bE[Y] E [ a X + bY ] = a E [ X ] + b E [ Y ]
LOTUS (law of the unconscious statistician) states
E [ g ( X ) ] = ∫ g ( x ) p ( x ) d x E[g(X)] = \int g(x) \, p(x) \, dx E [ g ( X )] = ∫ g ( x ) p ( x ) d x
e.g. E [ X 3 ] = ∫ x 3 p ( x ) d x E[X^3] = \int x^3 p(x) \, dx E [ X 3 ] = ∫ x 3 p ( x ) d x .
Variance
Variance is the measure of spread of an RV with a distribution,
V a r ( X ) = E [ ( X − E [ X ] ) 2 ] = E [ X 2 ] − E [ X ] 2 \mathrm{Var}(X) = E\big[(X - E[X])^2\big] = E[X^2] - E[X]^2 Var ( X ) = E [ ( X − E [ X ] ) 2 ] = E [ X 2 ] − E [ X ] 2
Expectation with Respect to a Distribution
E p ( x ) [ f ( X , … ) ] E_{p(x)}[f(X, \ldots)] E p ( x ) [ f ( X , … )] means take the expectation with respect to the distribution of X X X , that is p ( x ) p(x) p ( x ) . An equivalent form is E X ∼ p ( x ) [ f ( X , … ) ] E_{X \sim p(x)}[f(X, \ldots)] E X ∼ p ( x ) [ f ( X , … )] .
E.g. let X ∼ U n i f ( 0 , 1 ) X \sim \mathrm{Unif}(0,1) X ∼ Unif ( 0 , 1 ) , Y ∼ U n i f ( 0 , 2 ) Y \sim \mathrm{Unif}(0,2) Y ∼ Unif ( 0 , 2 ) , with X , Y X, Y X , Y independent. Then
E [ X Y ] = E X , Y [ X Y ] = E p ( x , y ) [ X Y ] = ∫ 0 2 ∫ 0 1 x y ⋅ 1 2 ⋅ 1 1 d x d y = 1 2 E[XY] = E_{X,Y}[XY] = E_{p(x,y)}[XY] = \int_0^2 \int_0^1 xy \cdot \frac{1}{2} \cdot \frac{1}{1} \, dx \, dy = \frac{1}{2} E [ X Y ] = E X , Y [ X Y ] = E p ( x , y ) [ X Y ] = ∫ 0 2 ∫ 0 1 x y ⋅ 2 1 ⋅ 1 1 d x d y = 2 1
But
E X [ X Y ] = ∫ 0 1 x Y ⋅ 1 1 d x = Y ∫ 0 1 x d x = Y 2 E_X[XY] = \int_0^1 xY \cdot \frac{1}{1} \, dx = Y \int_0^1 x \, dx = \frac{Y}{2} E X [ X Y ] = ∫ 0 1 x Y ⋅ 1 1 d x = Y ∫ 0 1 x d x = 2 Y
which is still a random variable.
Conditional Expectation
A conditional expectation E [ X ∣ Y ] E[X | Y] E [ X ∣ Y ] is itself a random variable, a function of Y Y Y , with
E [ X ∣ Y = y ] = ∫ x p ( x ∣ y ) d x E[X | Y = y] = \int x \, p(x | y) \, dx E [ X ∣ Y = y ] = ∫ x p ( x ∣ y ) d x
E.g. for the counting heads example (from here ),
E [ X ∣ Y = 0 ] = 0 ⋅ 1 2 + 1 ⋅ 1 2 = 1 2 E [ X ∣ Y = 1 ] = 1 ⋅ 1 2 + 2 ⋅ 1 2 = 3 2 so E [ X ∣ Y ] = { 1 / 2 if Y = 0 , with probability 1 / 2 3 / 2 if Y = 1 , with probability 1 / 2 \begin{aligned}
E[X | Y = 0] &= 0 \cdot \tfrac{1}{2} + 1 \cdot \tfrac{1}{2} = \tfrac{1}{2} \\
E[X | Y = 1] &= 1 \cdot \tfrac{1}{2} + 2 \cdot \tfrac{1}{2} = \tfrac{3}{2}
\end{aligned}
\qquad \text{so} \qquad
E[X | Y] =
\begin{cases}
1/2 & \text{if } Y = 0, \text{ with probability } 1/2 \\
3/2 & \text{if } Y = 1, \text{ with probability } 1/2
\end{cases} E [ X ∣ Y = 0 ] E [ X ∣ Y = 1 ] = 0 ⋅ 2 1 + 1 ⋅ 2 1 = 2 1 = 1 ⋅ 2 1 + 2 ⋅ 2 1 = 2 3 so E [ X ∣ Y ] = { 1/2 3/2 if Y = 0 , with probability 1/2 if Y = 1 , with probability 1/2
Tower Law states
E [ X ] = E Y [ E X ∣ Y [ X ∣ Y ] ] E[X] = E_Y\big[E_{X|Y}[X | Y]\big] E [ X ] = E Y [ E X ∣ Y [ X ∣ Y ] ]
i.e. first take the expectation given Y Y Y , which is an RV as a function of Y Y Y , then take the expectation over Y Y Y to get E [ X ] E[X] E [ X ] .
E.g. let X ∼ U n i f ( 0 , 1 ) X \sim \mathrm{Unif}(0,1) X ∼ Unif ( 0 , 1 ) and Y ∣ X ∼ N ( X , 1 ) Y | X \sim \mathcal{N}(X, 1) Y ∣ X ∼ N ( X , 1 ) . Then
E [ Y ] = E X [ E [ Y ∣ X ] ] = E X [ X ] = 1 2 E[Y] = E_X\big[E[Y | X]\big] = E_X[X] = \tfrac{1}{2} E [ Y ] = E X [ E [ Y ∣ X ] ] = E X [ X ] = 2 1
Covariance and Correlation
A measure of relation or dependence between random variables is covariance ,
C o v ( X , Y ) = E [ ( X − E [ X ] ) ( Y − E [ Y ] ) ] = E [ X Y ] − E [ X ] E [ Y ] \mathrm{Cov}(X, Y) = E\big[(X - E[X])(Y - E[Y])\big] = E[XY] - E[X]E[Y] Cov ( X , Y ) = E [ ( X − E [ X ]) ( Y − E [ Y ]) ] = E [ X Y ] − E [ X ] E [ Y ]
and C o v ( X , X ) = V a r ( X ) \mathrm{Cov}(X, X) = \mathrm{Var}(X) Cov ( X , X ) = Var ( X ) .
Correlation is a measure of linear relation between two RVs,
ρ X , Y = C o v ( X , Y ) V a r ( X ) V a r ( Y ) ∈ [ − 1 , 1 ] \rho_{X,Y} = \frac{\mathrm{Cov}(X, Y)}{\sqrt{\mathrm{Var}(X)\, \mathrm{Var}(Y)}} \in [-1, 1] ρ X , Y = Var ( X ) Var ( Y ) Cov ( X , Y ) ∈ [ − 1 , 1 ]
− 1 -1 − 1 or 1 1 1 means the RVs are linear transformations of each other, e.g. Y = 3 X + 2 Y = 3X + 2 Y = 3 X + 2 .
If X , Y X, Y X , Y are independent,
E [ X Y ] = E [ X ] E [ Y ] ⟹ C o v ( X , Y ) = 0 ⟹ ρ X , Y = 0 E[XY] = E[X]E[Y] \implies \mathrm{Cov}(X, Y) = 0 \implies \rho_{X,Y} = 0 E [ X Y ] = E [ X ] E [ Y ] ⟹ Cov ( X , Y ) = 0 ⟹ ρ X , Y = 0
But ρ X , Y = 0 \rho_{X,Y} = 0 ρ X , Y = 0 does not mean X , Y X, Y X , Y are independent.
Random Vectors
Instead of 1D RVs, we can define random vectors with each entry being an RV. Then
X = [ X 1 ⋮ X n ] , E [ X ] = [ E [ X 1 ] ⋮ E [ X n ] ] , C o v ( X ) = [ V a r ( X 1 ) ⋯ C o v ( X 1 , X n ) ⋮ ⋱ ⋮ C o v ( X n , X 1 ) ⋯ V a r ( X n ) ] ∈ R n × n X = \begin{bmatrix} X_1 \\ \vdots \\ X_n \end{bmatrix}, \qquad E[X] = \begin{bmatrix} E[X_1] \\ \vdots \\ E[X_n] \end{bmatrix}, \qquad \mathrm{Cov}(X) = \begin{bmatrix} \mathrm{Var}(X_1) & \cdots & \mathrm{Cov}(X_1, X_n) \\ \vdots & \ddots & \vdots \\ \mathrm{Cov}(X_n, X_1) & \cdots & \mathrm{Var}(X_n) \end{bmatrix} \in \mathbb{R}^{n \times n} X = X 1 ⋮ X n , E [ X ] = E [ X 1 ] ⋮ E [ X n ] , Cov ( X ) = Var ( X 1 ) ⋮ Cov ( X n , X 1 ) ⋯ ⋱ ⋯ Cov ( X 1 , X n ) ⋮ Var ( X n ) ∈ R n × n
The covariance matrix Σ = C o v ( X ) \Sigma = \mathrm{Cov}(X) Σ = Cov ( X ) is a symmetric, positive semidefinite matrix of the pairwise covariances.
Multivariate Normal
A multivariate normal is the distribution of a random vector where every linear combination of its entries is normally distributed. In particular each entry is normal, but normal entries alone are not enough.
It is specified as X ∼ N ( μ , Σ ) X \sim \mathcal{N}(\mu, \Sigma) X ∼ N ( μ , Σ ) , where μ \mu μ is the vector of means and Σ \Sigma Σ is the covariance matrix. If Σ \Sigma Σ is invertible, for n n n dimensional X X X
f X ( x ) = 1 ( 2 π ) n / 2 ∣ Σ ∣ 1 / 2 exp ( − 1 2 ( x − μ ) T Σ − 1 ( x − μ ) ) f_X(x) = \frac{1}{(2\pi)^{n/2} |\Sigma|^{1/2}} \exp\Big(-\frac{1}{2}(x - \mu)^T \Sigma^{-1} (x - \mu)\Big) f X ( x ) = ( 2 π ) n /2 ∣Σ ∣ 1/2 1 exp ( − 2 1 ( x − μ ) T Σ − 1 ( x − μ ) )
where ∣ Σ ∣ |\Sigma| ∣Σ∣ is the determinant. Also,
A X + b ∼ N ( A μ + b , A Σ A T ) AX + b \sim \mathcal{N}(A\mu + b,\ A\Sigma A^T) A X + b ∼ N ( A μ + b , A Σ A T )