# Random Variables and their Distributions

{% hint style="info" %}

#### Definition 5

A random variable is a function $$X:\Omega\rightarrow\mathbb{R}$$ with the property $$\forall \alpha\in\mathbb{R},\ {\omega\in\Omega:\ X(\omega) \leq \alpha} \in \mathcal{F}$$.
{% endhint %}

The condition in Definition 5 is necessary to compute $$P(X\leq \alpha),\ \forall \alpha\in\mathbb{R}$$. This requirement also let us compute $$P(X\in B)$$ for most sets by leveraging the fact that $$\mathcal{F}$$ is closed under complements, unions, and intersections. For example, we can also compute $$P(X > \alpha)$$ and $$P(\alpha < X \leq \beta)$$. In this sense, the property binds the probability space to the random variable.

Definition 5 also implies that random variables satisfy particular algebraic properties. For example, if $$X,Y$$ are random variables, then so are $$X+Y, XY, X^p, \lim\_{n\to\infty}X\_n$$, etc.

{% hint style="info" %}

#### Definition 6

A discrete random variable is a random variable whose codomain is countable.
{% endhint %}

{% hint style="info" %}

#### Definition 7

A continuous random variable is a random variable whose codomain is the real numbers.
{% endhint %}

Although random variables are defined based on a probability space, it is often most natural to model problems without explicitly specifying the probability space. This works so long as we specify the random variables and their distribution in a “consistent” way. This is formalized by the so-called [Kolmogorov Extension Theorem](https://en.wikipedia.org/wiki/Kolmogorov_extension_theorem) but can largely be ignored.

## Distributions

Roughly speaking, the distribution of a random variable gives an idea of the likelihood that a random variable takes a particular value or set of values.

{% hint style="info" %}

#### Definition 8

The probability mass function (or distribution) of a discrete random variable $$X$$ is the frequency with which $$X$$ takes on different values.

$$p\_X:\mathcal{X} \rightarrow \[0, 1] \text{ where } \mathcal{X} = \text{range}(X),\qquad p\_X(x) = \text{Pr}\left{X=x\right} .$$
{% endhint %}

Note that $$\sum\_{x\in\mathcal{X}}p\_X(x) = 1$$ since $$\bigcap\_{x\in\mathcal{X}}{w: X(w) = x} = \Omega$$.

Continuous random variables are largely similar to discrete random variables. One key difference is that instead of being described by a probability “mass”, they are instead described by a probability “density”.

{% hint style="info" %}

#### Definition 9

The probability density function (distribution) of a continuous random variable describes the density by which a random variable takes a particular value.

$$f\_X: \mathbb{R}\to \[0, \infty) \text{ where } \int\_{-\infty}^{\infty}f\_X(x)dx = 1 \text{ and } \text{Pr}\left{X\in B\right} = \int\_B f\_X(x)dx$$
{% endhint %}

Observe that if a random variable $$X$$ is continuous, then the probability that it takes on a particular value is zero.

$$\text{Pr}\left{X=x\right} = \lim\_{\delta\to0} \text{Pr}\left{x \leq X \leq x +\delta\right} = \lim\_{\delta\to 0}\int\_x^{x+\delta}f\_X(u)du = \int\_{x}^{x}f\_X(u)du = 0$$

{% hint style="info" %}

#### Definition 10

The cumulative distribution function (CDF) gives us the probability of a random variable $$X$$ being less than or equal to a particular value.

$$F\_X:\mathbb{R} \to \[0, 1],\quad F\_X(x) = \text{Pr}\left{X \leq x\right}$$
{% endhint %}

Note that by the Kolomogorov axioms, $$F\_X$$ must satisfy three properties:

1. $$F\_X$$ is non-decreasing.
2. $$\lim\_{x\to0} F\_X(x) = 0$$ and $$\lim\_{x\to\infty} F\_X(x) = 1$$.
3. $$F\_X$$ is right continuous.

It turns out that if we have any function $$F\_X$$ that satisfies these three properties, then it is the CDF of some random variable on some probability space. Note that $$F\_X(x)$$ gives us an alternative way to define continuous random variables. If $$F\_X(x)$$ is absolutely continuous, then it can be expressed as

$$F\_X(x) = \int\_{-\infty}^{x}f\_X(x)dx$$

for some non-negative function $$f\_X(x)$$, and this is the PDF of a continuous random variable.

Often, when modeling problems, there are multiple random variables that we want to keep track of.

{% hint style="info" %}

#### Definition 11

If $$X$$ and $$Y$$ are random variables on a common probability space $$(\Omega, \mathcal{F}, P)$$, then the joint distribution (denoted $$p\_{XY}(x, y)$$ or $$f\_{XY}(x, y)$$describes the frequencies of joint outcomes.
{% endhint %}

Note that it is possible for $$X$$ to be continuous and $$Y$$ to be discrete (or vice versa).

{% hint style="info" %}

#### Definition 12

The marginal distribution of a joint distribution is the distribution of a single random variable.

$$p\_X(x) = \sum\_yp\_{XY}(x, Y=y), \qquad f\_X(x) = \int\_{-\infty}^{\infty}f\_{XY}(x, y)dy$$
{% endhint %}

{% hint style="info" %}

#### Definition 13

Two random variables $$X$$ and $$Y$$are independent if their joint distribution is the product of the marginal distributions.
{% endhint %}

Just like independence, we can extend the notion of conditional probability to random variables.

{% hint style="info" %}

#### Definition 14

The conditional distribution of $$X$$ given $$Y$$ captures the frequencies of $$X$$ given we know the value of $$Y$$.

$$p\_{X|Y}(x|y) = \frac{P\_{XY}(x, y)}{p\_Y(y)}, \qquad f\_{X|Y}(x|y) = \frac{f\_{XY}(x, y)}{f\_Y(y)}$$
{% endhint %}

Often, we need to combine or transform several random variables. A derived distribution is the obtained by arithmetic of several random variables or applying a function to several (or many) random variables. Since the CDF of a distribution essentially defines that random variable, it can often be easiest to work backwards from the CDF to the PDF or PMF. In the special case where we want to find $$Y=g(X)$$ for a function $$g$$.

$$F\_y(y) =\text{Pr}\left{Y \leq y\right} = \text{Pr}\left{g(x) \leq y\right} = \text{Pr}\left{X \in g^{-1}(\[-\infty, y])\right} , \quad g^{-1}(y) = { x: g(x) = y }.$$

Another special case of a derived distribution is when adding random variables together.

{% hint style="info" %}

#### Theorem 5

The resulting distribution of a sum of two independent random variables is the convolution of the distributions of the two random variables.

$$p\_{X+Y}(z) = \sum\_{k=-\infty}^{\infty}p\_X(k)p\_Y(z-k), \quad f\_{X+Y}(z) = \int\_{-\infty}^{\infty}f\_X(x)f\_Y(z - x)dx$$
{% endhint %}

## Properties of Distributions

### Expectation

{% hint style="info" %}

#### Definition 15

The expectation of a random variable describes the center of a distribution,

$$\mathbb{E}\left\[X\right] =\sum\_{x\in\mathcal{X}}xp\_X(x), \quad \mathbb{E}\left\[X\right] = \int\_{-\infty}^{\infty}xf\_X(x)dx$$

provided the sum or integral converges.
{% endhint %}

Expectation has several useful properties. If we want to compute the expectation of a function of a random variable, then we can use the law of the unconscious statisitician.

{% hint style="info" %}

#### Theorem 6 (Law of the Unconscious Statistician) <a href="#theorem-6" id="theorem-6"></a>

$$\mathbb{E}\left\[g(X)\right] = \sum\_{x\in\mathcal{X}}g(x)p\_X(x), \quad \mathbb{E}\left\[g(X)\right] = \int\_{-\infty}^{\infty}g(x)f\_X(x)dx$$
{% endhint %}

Another useful property is its linearity.

$$\mathbb{E}\left\[aX+bY\right] = a\mathbb{E}\left\[X\right] +b\mathbb{E}\left\[Y\right] ,\ \forall a, b\in\mathbb{R}.$$

Sometimes it can be difficult to compute expectations directly. For disrete distributions, we can use the tail-sum formula.

{% hint style="info" %}

#### Theorem 7 (Tail Sum) <a href="#theorem-7" id="theorem-7"></a>

For a non-negative integer random variable,

$$\mathbb{E}\left\[X\right] = \sum\_{k=1}^{\infty}\text{Pr}\left{X\geq k\right} .$$
{% endhint %}

When two random variables are independent, expectation has some additional properties.

{% hint style="info" %}

#### Theorem 8

If $$X$$ and $$Y$$ are independent, then

$$\mathbb{E}\left\[XY\right] = \mathbb{E}\left\[X\right] \mathbb{E}\left\[Y\right] .$$
{% endhint %}

Earlier, we saw that we find a derived distribution by transforming and combining random variables. Sometimes, we don’t need to actually compute the distribution, but only some of its properties.

{% hint style="info" %}

#### Definition 16

The nth moment of a random variable is $$\mathbb{E}\left\[X^n\right]$$.
{% endhint %}

It turns out that we can encode the moments of a distribution into the coefficients of a special power series.

{% hint style="info" %}

#### Definition 17

The moment generating function of a random variable $$X$$ is given by $$M\_X(t) = \mathbb{E}\left\[e^{tX}\right]$$.
{% endhint %}

Notice that if we apply the power series expansion of $$e^{tX}$$, we see that

$$M\_X(t) = \sum\_{n=0}^{\infty}\frac{t!}{n!}\mathbb{E}\left\[X^n\right] .$$

Thus the nth moment is encoded in the coefficients of the power series and we can retrieve them by taking a derivative:

$$\mathbb{E}\left\[X^n\right] = \frac{d^{n}}{dt^{n}}M\_X(t).$$

Another interesting point to notice is that for a continuous random variable

$$M\_X(t) = \int\_{-\infty}^{\infty}f\_X(x)e^{tx}dx$$

is the Laplace transform of the distribution over the real line, and for a discrete random variable,

$$M\_X(t) = \sum\_{x=-\infty}^{\infty}p\_X(x)e^{tx}$$

is the Z-transform of the distribution evaluated along the curve at $$e^{-t}$$.

{% hint style="info" %}

#### Theorem 9

If the MGF of a function exists, then it uniquely determines the distribution.
{% endhint %}

This provides another way to compute the distribution for a sum of random variables because we can just multiply their MGF.

### Variance

{% hint style="info" %}

#### Definition 18

The variance of a discrete random variable $$X$$ describes its spread around the expectation and is given by

$$\text{Var}\left(X\right) = \mathbb{E}\left\[(X-\mathbb{E}\left\[X\right] )^2\right] = \mathbb{E}\left\[X^2\right] -\mathbb{E}\left\[X\right] ^2.$$
{% endhint %}

{% hint style="info" %}

#### Theorem 10

When two random variables $$X$$ and $$Y$$ are independent, then

$$\text{Var}\left(X+Y\right) = \text{Var}\left(X\right) + \text{Var}\left(Y\right) .$$
{% endhint %}

{% hint style="info" %}

#### Definition 19

The covariance of two random variables describes how much they depend on each other and is given by

$$\text{Cov}\left(X, Y\right) = \mathbb{E}\left\[(X-\mathbb{E}\left\[X\right] )(Y-\mathbb{E}\left\[Y\right] )\right] = \mathbb{E}\left\[XY\right] - \mathbb{E}\left\[X\right] \mathbb{E}\left\[Y\right] .$$
{% endhint %}

If $$\text{Cov}\left(X,Y\right) = 0$$ then $$X$$ and $$Y$$ are uncorrelated.

{% hint style="info" %}

#### Definition 20

The correlation coefficient gives a single number which describes how random variables are correlated.

$$ho(X, Y) = \frac{\text{Cov}\left(X, Y\right) }{\sqrt{\text{Var}\left(X\right) }\sqrt{\text{Var}\left(Y\right) }}.$$
{% endhint %}

Note that $$-1\leq \rho \leq 1$$.

## Common Discrete Distributions

{% hint style="info" %}

#### Definition 21

$$X$$ is uniformly distributed when each value of $$X$$ has equal probability.

$$X\sim \text{Uniform}({ 1, 2, \cdots, n }) \implies p\_X(x) = \begin{cases} \frac{1}{n} & x = 1, 2, \cdots, n,\ 0 & \text{ else.} \end{cases}$$
{% endhint %}

{% hint style="info" %}

#### Definition 22

$$X$$ is a Bernoulli random variable if it is either $$0$$ or $$1$$ with $$p\_X(1) = p$$.

$$X\sim\text{Bernoulli}(p) \implies p\_X(x) = \begin{cases} 1 - p & x=0,\ p & x=1,\ 0 & \text{ else.} \end{cases}$$

$$\mathbb{E}\left\[X\right] = p \qquad \text{Var}\left(X\right) = (1-p)p$$
{% endhint %}

Bernoulli random variables are good for modeling things like a coin flip where there is a probability of success. Bernoulli random variables are frequently used as indicator random variables $$\mathbb{1}\_A$$ where

$$\mathbb{1}\_A = \begin{cases} 1 & \text{if A occurs,}\ 0 & \text{ else.} \end{cases}$$

When paired with the linearity of expectation, this can be a powerful method of computing the expectation of something.

{% hint style="info" %}

#### Definition 23

$$X$$ is a Binomial random variable when

$$X \sim \text{Binomial}(n, p) \implies p\_X(x) = \begin{cases} \binom{n}{x} p^x (1-p)^{n-x} & x=0, 1, \cdots, n\ 0 & \text{ else.} \end{cases}$$

$$\mathbb{E}\left\[X\right] = np \qquad \text{Var}\left(X\right) = np(1-p)$$
{% endhint %}

A binomial random variable can be thought of as the number of successes in $$n$$ trials. In other words,

$$X \sim \text{Binomial}(n, p) \implies X = \sum\_{i=1}^{n}X\_i, \quad X\_i \sim \text{Bernoulli}(p).$$

By construction, if $$X\sim\text{Binomial}(n, p)$$ and $$Y\sim\text{Binomial}(m, p)$$ are independent, then $$X+Y \sim \text{Binomial}(m+n, p)$$.

{% hint style="info" %}

#### Definition 24

A Geometric random variable is distributed as

$$X\sim\text{Geom}(p) \implies p\_X(x) = \begin{cases} p(1-p)^{x-1} & x=1, 2, \cdots\ 0 & \text{ else}. \end{cases}$$

$$\mathbb{E}\left\[X\right] = \frac{1}{p} \qquad \text{Var}\left(X\right) = \frac{1-p}{p^2}$$
{% endhint %}

Geometric random variables are useful for modeling the number of trials required before the first success. In other words,

$$X \sim \text{Geom}(p) \implies X = \min{k \geq 1: X\_k=1 } \text{ where } X\_i\sim \text{Bernoulli}(p).$$

A useful property of geometric random variables is that they are memoryless:

$$\text{Pr}\left{X=K+M|X>k\right} = \text{Pr}\left{X=M\right} .$$

{% hint style="info" %}

#### Definition 25

A Poisson random variable is distributed as

$$X\sim Poisson(\lambda) \implies p\_X(x) = \begin{cases} \frac{\lambda^xe^{-\lambda}}{x!} & x=0, 1, \cdots \ 0 & \text{ else.} \end{cases}$$

$$\mathbb{E}\left\[X\right] = \lambda$$
{% endhint %}

Poisson random variables are good for modeling the number of arrivals in a given interval. Suppose you take a given time interval and divide it into $$n$$ chunks where the probability of arrival in chunk $$i$$ is $$X\_i \sim \text{Bernoulli}(p\_n)$$. Then the total number of arrivals $$X\_n = \sum\_{i=1}^{n}X\_i$$ is distributed as a Binomial random variable with expectation $$np\_n=\lambda$$. As we increase $$n$$ to infinity but keep $$\lambda$$ fixed, we arrive at the poisson distribution.

A useful fact about Poisson random variables is that if $$X\sim\text{Poisson}(\lambda)$$ and $$Y\sim\text{Poisson}(\mu)$$ are independent, then $$X+Y \sim \text{Poisson}(\lambda + \mu)$$.

## Common Continuous Distributions

{% hint style="info" %}

#### Definition 26

A continuous random variable is uniformly distributed when the pdf of $$X$$ is constant over a range.

$$X \sim \text{Uniform}(a, b) \implies f\_X(x) = \begin{cases} \frac{1}{b-a} & a \leq x \leq b,\ 0 & \text{ else.} \end{cases}$$
{% endhint %}

The CDF of a uniform distribution is given by

$$F\_X(x) = \begin{cases} 0, & x < a,\ \frac{x-a}{b-a}, & x\in\[a, b)\ 1, & x \geq b. \end{cases}$$

{% hint style="info" %}

#### Definition 27

A continuous random variable is exponentially distributed when its pdf is given by

$$X \sim \text{Exp}(\lambda) \implies f\_X(x) = \begin{cases} \lambda e^{-\lambda x} & x \geq 0,\ 0 & \text{ else.} \end{cases}$$
{% endhint %}

Exponential random variables are the only continuous random variable to have the memoryless property:

$$\text{Pr}\left{X > t+s | X > s\right} = \text{Pr}\left{X > t\right} , \quad t \geq 0.$$

The CDF of the exponential distribution is given by

$$F\_X(x) = \lambda \int\_0^{x}e^{-\lambda u}du = 1 - e^{-\lambda x}$$

{% hint style="info" %}

#### Definition 28

$$X$$ is a Gaussian Random Variable with mean $$\mu$$ and variance $$\sigma^2$$ (denoted $$X\sim \mathcal{N}(\mu, \sigma^2)$$) if it has the PDF

$$f\_X(x) = \frac{1}{\sqrt{2\pi\sigma^2}}e^{\frac{-(x-\mu)^2}{2\sigma^2}}$$
{% endhint %}

The standard normal is $$X\sim\mathcal{N}(0, 1)$$, and it has the CDF

$$\Phi(x) = \frac{1}{\sqrt{2\pi}}\int\_{-\infty}^{x}e^{\frac{-u^2}{2}} du$$

There is no closed from for $$\Phi(x)$$. It turns out that every normal random variable can be transformed into the standard normal (i.e $$\frac{X - \mu}{\sigma} \sim \mathcal{N}(0, 1)$$). Some facts about Gaussian random variables are

1. If $$X\sim\mathcal{N}(\mu\_x, \sigma\_x^2),\ Y\sim\mathcal{N}(\mu\_y, \sigma\_y^2)$$ are independent, then $$X+Y \sim \mathcal{N}(\mu\_x+\mu\_y, \sigma\_x^2 + \sigma\_y^2)$$.
2. If $$X,Y$$ are independent and $$(X+Y), (X-Y)$$ are independent, then both $$X$$ and $$Y$$ are Gaussian with the same variance.

### Jointly Gaussian Random Variables

Jointly Gaussian Random Varables, also known as Gaussian Vectors, can be defined in a variety of ways.

{% hint style="info" %}

#### Definition 29

A Gaussian Random Vector $$\boldsymbol{X} = \begin{bmatrix} X\_1 & \cdots & X\_n \end{bmatrix}^T$$ with density on $$\mathbb{R}^n$$, $$\text{Cov}\left(\boldsymbol{X}\right) =\Sigma, \mathbb{E}\left\[X\right] =\boldsymbol{\mu}$$ is defined by the pdf

$$f\_{\boldsymbol{X}}(\boldsymbol{x}) = \frac{1}{\sqrt{(2\pi)^n\text{det}(\Sigma)}}e^{-\frac{1}{2}(\boldsymbol{x}-\boldsymbol{\mu})^T\Sigma^{-1}(\boldsymbol{x}-\boldsymbol{\mu})}$$
{% endhint %}

{% hint style="info" %}

#### Definition 30

A joint gaussian random variable is an affine transformation of independent and identically distributed standard normals.

$$\boldsymbol{X} = \boldsymbol{\mu}+A\boldsymbol{W}$$

where $$A=\Sigma^{1/2}$$ is a full-rank matrix and $$\boldsymbol{W}$$is a vector of i.i.d standard normals.
{% endhint %}

{% hint style="info" %}

#### Definition 31

A random variable is jointly gaussian if all 1D projections are Gaussian

$$\boldsymbol{a}^T\boldsymbol{X} \sim \mathcal{N}(\boldsymbol{a}^T\boldsymbol{\mu}, \boldsymbol{a}^T\Sigma\boldsymbol{a})$$
{% endhint %}

In addition to their many definitions, jointly gaussian random variables also have interesting properties.

{% hint style="info" %}

#### Theorem 11

If $$\boldsymbol{X}$$ and $$\boldsymbol{Y}$$ are jointly gaussian random variables, then

$$X = \mu\_{\boldsymbol{X}}+\Sigma\_{\boldsymbol{XY}}\Sigma\_{\boldsymbol{Y}}^{-1}(\boldsymbol{Y} - \boldsymbol{\mu\_Y}) + \boldsymbol{V} \text{ where } V \sim \mathcal{N}(0, \Sigma\_X-\Sigma\_{\boldsymbol{XY}}\Sigma\_Y^{-1}\Sigma{\boldsymbol{YX}})$$
{% endhint %}

Theorem 11 tells us that each entry in Gaussian Vector can be thought of as a “noisy” version of the others.

## Hilbert Spaces of Random Variables

One way to understand random variables is through linear algebra by thinking of them as vectors in a vector space.

{% hint style="info" %}

#### Definition 32

An real inner product space $$V$$ is composed of a vector space $$V$$ over a real scalar field equipped with an inner product $$\langle \cdot,\cdot \rangle$$ that satisfies $$\forall u,v,w\in V$$, $$a, b\in\mathbb{R}$$,

1. $$\langle u, v \rangle = \langle v, u \rangle$$
2. $$\langle au + bv, w \rangle = a \langle u,w \rangle + b \langle v,w \rangle$$
3. $$\langle u,u \rangle \geq 0$$ and $$\<u,u> = 0 \Leftrightarrow u = 0$$
   {% endhint %}

Inner products spaces are equipped with the norm $$|v| = \sqrt{\langle v, v \rangle }$$.

{% hint style="info" %}

#### Definition 33

A Hilbert Space is a real inner product space that is complete with respect to its norm.
{% endhint %}

Loosely, completeness means that we can take limits of without exiting the space. It turns out that random variables satisfy the definition of a Hilbert Space.

{% hint style="info" %}

#### Theorem 12

Let $$(\Omega, \mathcal{F}, P)$$ be a probability space. The collection of random variables $$X$$ with $$\mathbb{E}\left\[X^2\right] < \infty$$ on this probability space form a Hilbert Space with respect to the inner product $$\langle X, Y \rangle = \mathbb{E}\left\[XY\right]$$.
{% endhint %}

Hilbert spaces are important because they provide a notion of geometry that is compatible with our intuition as well as the geometry of $$\mathbb{R}^n$$ (which is a Hilbert Space). One geometric idea is that of orthogonality. Two vectors are orthogonal if $$\langle X, Y\rangle = 0$$. Two random variables will be orthogonal if they are zero-mean and uncorrelated. Using orthogonality, we can also define projections.

{% hint style="info" %}

#### Theorem 13 (Hilbert Projection Theorem) <a href="#theorem-13" id="theorem-13"></a>

Let $$\mathcal{H}$$ be a Hilbert Space and $$\mathcal{U} \subseteq \mathcal{H}$$ be a closed subspace. For each vector $$v\in\mathcal{H}$$, $$\text{argmin} |u-v|$$ has a unique solution (there is a unique closest point $$u\in\mathcal{U}$$ to $$v$$). If $$u$$ is the closest point to $$v$$, then $$\forall u\in\mathcal{U},\ \langle u-v, u'\rangle$$.
{% endhint %}

Theorem 13 is what gives rise to important properties like the Pythogorean Theorem for any Hilbert Space.

$$|u|^2 + |u-v|^2 = |v| \text{ where } u=\text{argmin}|u-v|.$$

Suppose we had to random variables $$X$$ and $$Y$$. What happens if we try and project one onto the other?

{% hint style="info" %}

#### Definition 34

The conditional expectation of $$X$$ given $$Y$$ is the bounded continuous function of $$Y$$ such that $$X - \mathbb{E}\left\[X|Y\right]$$is orthogonal to all other bounded continuous functions $$\phi(Y)$$.

$$\forall \phi,\ \mathbb{E}\left\[(X-\mathbb{E}\left\[X|Y\right] )\phi(Y)\right] = 0.$$
{% endhint %}

Thus, the conditional expectation is the function of $$Y$$ that is closest to $$X$$. It’s interpretation is that the expectation of $$X$$ can change after observing some other random variable $$Y$$. To find $$\mathbb{E}\left\[X|Y\right]$$, we can use the conditional distribution of $$X$$ and $$Y$$.

{% hint style="info" %}

#### Theorem 14

The conditional expectation of a conditional distribution is given by

$$\mathbb{E}\left\[X|Y=y\right] = \sum\_{x\in\mathcal{X}}xp\_{X|Y}(x|y), \quad \mathbb{E}\left\[X|Y=y\right] = \int\_{-\infty}^{\infty}xf\_{X|Y}(x, y)dx$$

\label{defn:drv-conditional-expect}
{% endhint %}

Notice that $$\mathbb{E}\left\[X|Y\right]$$is a function of the random variable $$Y$$, meaning we can apply Theorem 6.

{% hint style="info" %}

#### Theorem 15 (Tower Property) <a href="#theorem-15" id="theorem-15"></a>

For all functions $$f$$,

$$\mathbb{E}\left\[f(Y)X\right] = \mathbb{E}\left\[f(Y)\mathbb{E}\left\[X|Y\right] \right]$$
{% endhint %}

Alternatively, we could apply lineary of expectation to Definition 34 to arrive at the same result. If we apply Theorem 15 to the function $$f(Y) = 1$$, then we can see that $$\mathbb{E}\left\[\mathbb{E}\left\[X|Y\right] \right] = \mathbb{E}\left\[X\right]$$.

Just as expectation can change when we know additional information, so can variance.

{% hint style="info" %}

#### Definition 35

Conditional Variance is the variance of $$X$$ given the value of $$Y$$.

$$\text{Var}\left(X|Y=y\right) = \mathbb{E}\left\[(X - \mathbb{E}\left\[X|Y=y\right] )^2 | Y=y\right] = \mathbb{E}\left\[X^2|Y=y\right] - \mathbb{E}\left\[X|Y=y\right] ^2$$
{% endhint %}

Conditional variance is a random variable just as expectation is.

{% hint style="info" %}

#### Theorem 16 (Law of Total Variance) <a href="#theorem-16" id="theorem-16"></a>

$$\text{Var}\left(X\right) = \mathbb{E}\left\[\text{Var}\left(X|Y\right) \right] + \text{Var}\left(\mathbb{E}\left\[X|Y\right] \right)$$
{% endhint %}

The second term in the law of total variance ($$\text{Var}\left(\mathbb{E}\left\[X|Y\right] \right)$$) can be interpreted as on average, how much uncertainty there is in $$X$$ given we know $$Y$$.
