Week 4: Transformations and Expectations
Week 4: Transformations and Expectations
Reading: Casella & Berger (C&B) §§2.1–2.2
| Lecture | Date | Topics | C&B |
|---|---|---|---|
| 4.1 | Tue. Oct. 20 | Distributions of functions of a random variable: the discrete case, the cdf method, monotone transformations, piecewise-monotone transformations | §2.1 |
| 4.2 | Thu. Oct. 22 | The probability integral transformation; expected values; linearity and properties of expectation; $\mathrm{E}X$ as the best predictor | §§2.1–2.2 |
Notation.
- $Y = g(X)$ is a function of the random variable $X$.
- $\mathcal{X}$ and $\mathcal{Y}$ are the support sets of $X$ and $Y$, as in (2.1.7).
- $g^{-1}$ is the inverse mapping, defined on sets in (2.1.1).
- $\mathrm{E}\,g(X)$ is the expected value of $g(X)$.
Where we are. In Week 3 we learned to describe a single random variable $X$ by its cdf $F_X$ and its pmf or pdf $f_X$. This week answers two natural follow-up questions:
- If we know the distribution of $X$, what is the distribution of $Y = g(X)$?
- What single number summarizes the “center” of a distribution?
Distributions of Functions of a Random Variable
Way of thinking. Don’t transform the density; transform the event.
1. The inverse mapping and the discrete case
If $X$ is a random variable, then any function $g(X)$ is also a random variable (it is still a function from $S$ into the real numbers). Writing $y = g(x)$, the function $g(x)$ defines a mapping from the sample space $\mathcal{X}$ of $X$ to a new sample space $\mathcal{Y}$, the sample space of $Y$:
\[g(x) : \mathcal{X} \to \mathcal{Y}.\]Support sets. To avoid confusion, always keep track of where the random variables live. For $Y = g(X)$ it is most convenient to use
\[\begin{aligned} \mathcal{X} &= \lbrace x : f_X(x) > 0 \rbrace \quad \text{and} \\ \mathcal{Y} &= \lbrace y : y = g(x) \text{ for some } x \in \mathcal{X} \rbrace. \end{aligned} \tag{2.1.7}\]The set where a pdf (or pmf, or any nonnegative function) is positive is called its support set, or simply its support.
We associate with $g$ an inverse mapping $g^{-1}$, which maps subsets of $\mathcal{Y}$ to subsets of $\mathcal{X}$:
\[g^{-1}(A) = \lbrace x \in \mathcal{X} : g(x) \in A \rbrace. \tag{2.1.1}\]About $g^{-1}$:
- It takes sets into sets.
- It exists even when $g$ is not one-to-one.
- For a point set, we write $g^{-1}(y) = \lbrace x \in \mathcal{X} : g(x) = y \rbrace$.
- This set can contain several points.
- If it contains exactly one point $x$, we write $g^{-1}(y) = x$.
The distribution of $Y = g(X)$ is then determined by that of $X$: for any set $A \subset \mathcal{Y}$,
\[\begin{aligned} P(Y \in A) &= P(g(X) \in A) \\ &= P\big( \lbrace x \in \mathcal{X} : g(x) \in A \rbrace \big) \\ &= P\big( X \in g^{-1}(A) \big). \end{aligned} \tag{2.1.2}\]This is the same idea as the induced probability (1.4.2) from Week 3, applied one level up.
Discrete case. If $X$ is discrete, then $\mathcal{X}$ is countable, so $\mathcal{Y} = \lbrace y : y = g(x), \ x \in \mathcal{X} \rbrace$ is countable and $Y$ is discrete. From (2.1.2), the pmf of $Y$ is
\[\begin{aligned} f_Y(y) = P(Y = y) &= \sum_{x \in g^{-1}(y)} P(X = x) \\ &= \sum_{x \in g^{-1}(y)} f_X(x), \quad \text{for } y \in \mathcal{Y}, \end{aligned}\]and $f_Y(y) = 0$ for $y \notin \mathcal{Y}$. So, for each $y \in \mathcal{Y}$:
- identify the set $g^{-1}(y)$;
- add up $f_X(x)$ over the points $x$ in that set.
Example 2.1.1 (Binomial transformation). A discrete random variable $X$ has a binomial distribution if its pmf is of the form
\[f_X(x) = P(X = x) = \binom{n}{x} p^x (1 - p)^{n - x}, \quad x = 0, 1, \dots, n, \tag{2.1.3}\]where $n$ is a positive integer and $0 \le p \le 1$. Values such as $n$ and $p$ that can be set to different values, producing different probability distributions, are called parameters.
Consider $Y = g(X)$ with $g(x) = n - x$, so $Y = n - X$.
- Here $\mathcal{X} = \mathcal{Y} = \lbrace 0, 1, \dots, n \rbrace$.
- $g^{-1}(y)$ is the single point $x = n - y$.
So
\[f_Y(y) = f_X(n - y) = \binom{n}{n - y} p^{n-y} (1 - p)^{y} = \binom{n}{y} (1 - p)^{y} p^{n - y},\]using $\binom{n}{y} = \binom{n}{n-y}$ (Definition 1.2.17).
- Thus $Y$ is also binomial, with parameters $n$ and $1 - p$.
- Interpretation: if $X$ counts heads, $Y$ counts tails.
2. The cdf method
For continuous $X$, the cdf of $Y = g(X)$ is
\[\begin{aligned} F_Y(y) &= P(Y \le y) = P(g(X) \le y) \\ &= P\big( \lbrace x \in \mathcal{X} : g(x) \le y \rbrace \big) \\ &= \int_{\lbrace x \in \mathcal{X} : \, g(x) \le y \rbrace} f_X(x)\, dx. \end{aligned} \tag{2.1.4}\]The hard part is identifying the set $\lbrace x \in \mathcal{X} : g(x) \le y \rbrace$.
Example 2.1.2 (Uniform transformation). Suppose $X$ has a uniform distribution on $(0, 2\pi)$, that is, $f_X(x) = 1/(2\pi)$ for $0 < x < 2\pi$ and $0$ otherwise. Consider $Y = \sin^2(X)$.
For $0 < y < 1$, the line at height $y$ crosses $\sin^2(x)$ at four points $x_1 < x_2 < \pi < x_3 < x_4$ (C&B Figure 2.1.1), and
\[P(Y \le y) = P(X \le x_1) + P(x_2 \le X \le x_3) + P(X \ge x_4). \tag{2.1.5}\]By the symmetry of $\sin^2(x)$ and the uniformity of $X$,
\[P(Y \le y) = 2P(X \le x_1) + 2P(x_2 \le X \le \pi), \tag{2.1.6}\]where $x_1$ and $x_2$ are the two solutions to $\sin^2(x) = y$, $0 < x < \pi$.
- Even this simple-looking transformation leads to a cdf that takes some work.
- Carrying it through with $x_1 = \arcsin \sqrt{y}$ and $x_2 = \pi - x_1$ gives $F_Y(y) = \frac{2}{\pi} \arcsin \sqrt{y}$ for $0 < y < 1$ (see Exercise 2.5).
Support sets. To avoid confusion, always keep track of where the random variables live. For $Y = g(X)$ it is most convenient to use
\[\begin{aligned} \mathcal{X} &= \lbrace x : f_X(x) > 0 \rbrace \quad \text{and} \\ \mathcal{Y} &= \lbrace y : y = g(x) \text{ for some } x \in \mathcal{X} \rbrace. \end{aligned} \tag{2.1.7}\]The set where a pdf (or pmf, or any nonnegative function) is positive is called its support set, or simply its support.
3. Monotone transformations
$g$ is monotone if it is either
- increasing: $u > v \Rightarrow g(u) > g(v)$, or
- decreasing: $u < v \Rightarrow g(u) > g(v)$.
A monotone $g$ is one-to-one and onto from $\mathcal{X}$ to $\mathcal{Y}$, so $g^{-1}$ is single-valued: $g^{-1}(y) = x$ if and only if $y = g(x)$. Then
\[\lbrace x \in \mathcal{X} : g(x) \le y \rbrace = \lbrace x \in \mathcal{X} : x \le g^{-1}(y) \rbrace \quad \text{if } g \text{ is increasing}, \tag{2.1.8}\] \[\lbrace x \in \mathcal{X} : g(x) \le y \rbrace = \lbrace x \in \mathcal{X} : x \ge g^{-1}(y) \rbrace \quad \text{if } g \text{ is decreasing}. \tag{2.1.9}\](A decreasing function reverses inequalities: draw a graph to see why.)
Theorem 2.1.3. Let $X$ have cdf $F_X(x)$, let $Y = g(X)$, and let $\mathcal{X}$ and $\mathcal{Y}$ be defined as in (2.1.7).
- a. If $g$ is an increasing function on $\mathcal{X}$, $F_Y(y) = F_X\big( g^{-1}(y) \big)$ for $y \in \mathcal{Y}$.
- b. If $g$ is a decreasing function on $\mathcal{X}$ and $X$ is a continuous random variable, $F_Y(y) = 1 - F_X\big( g^{-1}(y) \big)$ for $y \in \mathcal{Y}$.
Why.
- Increasing $g$: by (2.1.8), $F_Y(y) = P(X \le g^{-1}(y)) = F_X(g^{-1}(y))$.
- Decreasing $g$: by (2.1.9), $F_Y(y) = P(X \ge g^{-1}(y)) = 1 - F_X(g^{-1}(y))$. The last step uses continuity: $P(X = g^{-1}(y)) = 0$.
Example 2.1.4 (Uniform-exponential relationship–I). Suppose $X \sim f_X(x) = 1$ if $0 < x < 1$ and $0$ otherwise, the uniform(0, 1) distribution, so $F_X(x) = x$ for $0 < x < 1$. Let $Y = g(X) = -\log X$. Since
\[\frac{d}{dx} g(x) = \frac{d}{dx}(-\log x) = -\frac{1}{x} < 0, \quad \text{for } 0 < x < 1,\]$g$ is decreasing, and $\mathcal{Y} = (0, \infty)$.
- For $y > 0$, $y = -\log x$ implies $x = e^{-y}$, so $g^{-1}(y) = e^{-y}$.
-
By Theorem 2.1.3(b),
\[F_Y(y) = 1 - F_X\big( g^{-1}(y) \big) = 1 - F_X(e^{-y}) = 1 - e^{-y}.\] - Of course $F_Y(y) = 0$ for $y \le 0$.
Note that we only needed $g$ to be monotone on $(0, 1)$, the support of $X$.
Theorem 2.1.5. Let $X$ have pdf $f_X(x)$ and let $Y = g(X)$, where $g$ is a monotone function. Let $\mathcal{X}$ and $\mathcal{Y}$ be defined by (2.1.7). Suppose that $f_X(x)$ is continuous on $\mathcal{X}$ and that $g^{-1}(y)$ has a continuous derivative on $\mathcal{Y}$. Then the pdf of $Y$ is given by
\[f_Y(y) = \begin{cases} f_X\big( g^{-1}(y) \big) \left\lvert \dfrac{d}{dy} g^{-1}(y) \right\rvert & y \in \mathcal{Y} \\[2ex] 0 & \text{otherwise.} \end{cases} \tag{2.1.10}\]Proof. From Theorem 2.1.3, by the chain rule,
\[f_Y(y) = \frac{d}{dy} F_Y(y) = \begin{cases} f_X\big( g^{-1}(y) \big) \dfrac{d}{dy} g^{-1}(y) & \text{if } g \text{ is increasing} \\[2ex] -f_X\big( g^{-1}(y) \big) \dfrac{d}{dy} g^{-1}(y) & \text{if } g \text{ is decreasing,} \end{cases}\]which can be expressed concisely as (2.1.10). $\square$
Why the absolute value.
- $f_X(g^{-1}(y))$ says where $y$ comes from.
- The factor $\lvert dx/dy \rvert$ says how much $g$ stretches or squeezes a small interval.
- Probability is conserved: $f_Y(y)\, \lvert dy \rvert = f_X(x)\, \lvert dx \rvert$.
- Densities are never negative, so the factor must be $\lvert dx/dy \rvert$, not $dx/dy$.
Example 2.1.6 (Inverted gamma pdf). Let $f_X(x)$ be the gamma pdf
\[f(x) = \frac{1}{(n-1)!\, \beta^n} x^{n-1} e^{-x/\beta}, \quad 0 < x < \infty,\]where $\beta$ is a positive constant and $n$ is a positive integer. To find the pdf of $g(X) = 1/X$, note that
- $\mathcal{X} = \mathcal{Y} = (0, \infty)$;
- $g^{-1}(y) = 1/y$;
- $\frac{d}{dy} g^{-1}(y) = -1/y^2$.
By Theorem 2.1.5, for $y \in (0, \infty)$,
\[\begin{aligned} f_Y(y) &= f_X\big( g^{-1}(y) \big) \left\lvert \frac{d}{dy} g^{-1}(y) \right\rvert = \frac{1}{(n-1)!\, \beta^n} \left( \frac{1}{y} \right)^{n-1} e^{-1/(\beta y)} \frac{1}{y^2} \\ &= \frac{1}{(n-1)!\, \beta^n} \left( \frac{1}{y} \right)^{n+1} e^{-1/(\beta y)}, \end{aligned}\]a special case of the inverted gamma pdf.

Figure. The gamma pdf of $X$ (left) and the inverted gamma pdf of $Y = 1/X$ (right), with $n = 3$ and $\beta = 0.5, 1, 2$.
- Left: a larger $\beta$ spreads $X$ to the right. The mean is $n\beta$ and the mode is $(n - 1)\beta$.
- Right: taking reciprocals reverses the order. A larger $\beta$ pushes $Y$ toward 0, with mode $1/\big( (n + 1)\beta \big)$.
- Large values of $X$ become small values of $Y$, and the factor $1/y^2$ from the Jacobian reshapes the curve. $f_Y$ is not simply $f_X(1/y)$.
4. Piecewise-monotone transformations
Often $g$ is neither increasing nor decreasing, but it is monotone on pieces. (If $g$ is not monotone over certain intervals, then, as C&B put it, “we are in deep trouble.”)
Example 2.1.7 (Square transformation). Suppose $X$ is a continuous random variable. For $y > 0$, the cdf of $Y = X^2$ is
\[F_Y(y) = P(Y \le y) = P(X^2 \le y) = P(-\sqrt{y} \le X \le \sqrt{y}).\]Because $X$ is continuous, we can drop the equality from the left endpoint:
\[\begin{aligned} F_Y(y) &= P(-\sqrt{y} < X \le \sqrt{y}) \\ &= P(X \le \sqrt{y}) - P(X \le -\sqrt{y}) \\ &= F_X(\sqrt{y}) - F_X(-\sqrt{y}). \end{aligned}\]Differentiating, with the chain rule for each term,
\[\begin{aligned} f_Y(y) &= \frac{d}{dy} \big[ F_X(\sqrt{y}) - F_X(-\sqrt{y}) \big] \\ &= \frac{1}{2\sqrt{y}} f_X(\sqrt{y}) + \frac{1}{2\sqrt{y}} f_X(-\sqrt{y}), \end{aligned}\]so
\[f_Y(y) = \frac{1}{2\sqrt{y}} \big( f_X(\sqrt{y}) + f_X(-\sqrt{y}) \big). \tag{2.1.11}\]The pdf of $Y$ is a sum of two pieces, one for each interval on which $g(x) = x^2$ is monotone. In general, this will be the case.
Theorem 2.1.8. Let $X$ have pdf $f_X(x)$, let $Y = g(X)$, and define the sample space $\mathcal{X}$ as in (2.1.7). Suppose there exists a partition, $A_0, A_1, \dots, A_k$, of $\mathcal{X}$ such that $P(X \in A_0) = 0$ and $f_X(x)$ is continuous on each $A_i$. Further, suppose there exist functions $g_1(x), \dots, g_k(x)$, defined on $A_1, \dots, A_k$, respectively, satisfying
- i. $g(x) = g_i(x)$, for $x \in A_i$,
- ii. $g_i(x)$ is monotone on $A_i$,
- iii. the set $\mathcal{Y} = \lbrace y : y = g_i(x) \text{ for some } x \in A_i \rbrace$ is the same for each $i = 1, \dots, k$, and
- iv. $g_i^{-1}(y)$ has a continuous derivative on $\mathcal{Y}$, for each $i = 1, \dots, k$.
Then
\[f_Y(y) = \begin{cases} \displaystyle\sum_{i=1}^{k} f_X\big( g_i^{-1}(y) \big) \left\lvert \frac{d}{dy} g_i^{-1}(y) \right\rvert & y \in \mathcal{Y} \\[2ex] 0 & \text{otherwise.} \end{cases}\]Reading the theorem.
- Split $\mathcal{X}$ into pieces $A_1, \dots, A_k$ on which $g$ is monotone.
- Each $g_i$ is a one-to-one map from $A_i$ onto $\mathcal{Y}$, so each $y$ has exactly one “pre-image” $g_i^{-1}(y)$ in each piece.
- $f_Y(y)$ adds up the contributions from all the pieces.
- The “exceptional set” $A_0$ has probability 0. It is a technical device for handling endpoints such as $x = 0$ below.
- See Exercise 2.7 for an extension.
Example 2.1.9 (Normal-chi squared relationship). Let $X$ have the standard normal distribution,
\[f_X(x) = \frac{1}{\sqrt{2\pi}} e^{-x^2/2}, \quad -\infty < x < \infty,\]and let $Y = X^2$. The function $g(x) = x^2$ is monotone on $(-\infty, 0)$ and on $(0, \infty)$, and $\mathcal{Y} = (0, \infty)$. Take
\[\begin{aligned} A_0 &= \lbrace 0 \rbrace; \\ A_1 &= (-\infty, 0), & g_1^{-1}(y) &= -\sqrt{y}; \\ A_2 &= (0, \infty), & g_2^{-1}(y) &= \sqrt{y}. \end{aligned}\]By Theorem 2.1.8,
\[\begin{aligned} f_Y(y) &= \frac{1}{\sqrt{2\pi}} e^{-(-\sqrt{y})^2/2} \left\lvert -\frac{1}{2\sqrt{y}} \right\rvert + \frac{1}{\sqrt{2\pi}} e^{-(\sqrt{y})^2/2} \left\lvert \frac{1}{2\sqrt{y}} \right\rvert \\ &= \frac{1}{\sqrt{2\pi}} \frac{1}{\sqrt{y}} e^{-y/2}, \quad 0 < y < \infty. \end{aligned}\]This is the pdf of a chi squared random variable with 1 degree of freedom, which we will meet often.
Check your understanding.
-
Let $X \sim$ uniform(0, 1) and $Y = X^2$. Find $F_Y$ and $f_Y$ in two ways: by the cdf method, and by Theorem 2.1.5. Is $f_Y$ bounded?
Show answer
On $(0, 1)$, $g(x) = x^2$ is increasing, so $F_Y(y) = P(X \le \sqrt{y}) = \sqrt{y}$ for $0 < y < 1$. By Theorem 2.1.5 with $g^{-1}(y) = \sqrt{y}$: $f_Y(y) = 1 \cdot \frac{1}{2\sqrt{y}}$, $0 < y < 1$, which matches $\frac{d}{dy} \sqrt{y}$. It is unbounded near $y = 0$, yet still integrates to 1: a pdf is not a probability.
-
Let $X$ have pdf $f_X$ and $Y = aX + b$ with $a \ne 0$. Show that $f_Y(y) = \frac{1}{\lvert a \rvert} f_X\left( \frac{y - b}{a} \right)$.
Show answer
$g(x) = ax + b$ is monotone (increasing if $a > 0$, decreasing if $a < 0$), with $g^{-1}(y) = (y - b)/a$ and $\frac{d}{dy} g^{-1}(y) = 1/a$. Theorem 2.1.5 gives the formula. This is the basis of the location–scale families in Chapter 3.
-
Let $X$ be the number of heads in 3 tosses of a fair coin and $Y = (X - 1)^2$. Find the pmf of $Y$.
Show answer
$g^{-1}(0) = \lbrace 1 \rbrace$, $g^{-1}(1) = \lbrace 0, 2 \rbrace$, $g^{-1}(4) = \lbrace 3 \rbrace$. So $f_Y(0) = 3/8$, $f_Y(1) = 1/8 + 3/8 = 1/2$, and $f_Y(4) = 1/8$. Two values of $x$ map to $y = 1$, so their probabilities add.
The Probability Integral Transformation and Expected Values
Way of thinking. The expected value is a probability-weighted average.
5. The probability integral transformation
Theorem 2.1.10 (Probability integral transformation). Let $X$ have continuous cdf $F_X(x)$ and define the random variable $Y$ as $Y = F_X(X)$. Then $Y$ is uniformly distributed on $(0, 1)$, that is, $P(Y \le y) = y$, $0 < y < 1$.
The inverse cdf.
-
If $F_X$ is strictly increasing, then $F_X^{-1}$ is well defined by
\[F_X^{-1}(y) = x \iff F_X(x) = y. \tag{2.1.12}\] - But if $F_X$ is constant on some interval $[x_1, x_2]$, then every $x$ in that interval satisfies $F_X(x) = y$ (C&B Figure 2.1.2b), and (2.1.12) does not define a single value.
-
This is avoided by defining, for $0 < y < 1$,
\[F_X^{-1}(y) = \inf \lbrace x : F_X(x) \ge y \rbrace. \tag{2.1.13}\]This agrees with (2.1.12) when $F_X$ is nonconstant, and it is single-valued even when $F_X$ is not strictly increasing.
- At the endpoints: $F_X^{-1}(1) = \infty$ if $F_X(x) < 1$ for all $x$, and, for any $F_X$, $F_X^{-1}(0) = -\infty$.
Proof of Theorem 2.1.10. For $Y = F_X(X)$ and $0 < y < 1$,
\[\begin{aligned} P(Y \le y) &= P\big( F_X(X) \le y \big) \\ &= P\big( F_X^{-1}[F_X(X)] \le F_X^{-1}(y) \big) && (F_X^{-1} \text{ is increasing}) \\ &= P\big( X \le F_X^{-1}(y) \big) && (\text{see below}) \\ &= F_X\big( F_X^{-1}(y) \big) && (\text{definition of } F_X) \\ &= y. && (\text{continuity of } F_X) \end{aligned}\]At the endpoints, $P(Y \le y) = 1$ for $y \ge 1$ and $P(Y \le y) = 0$ for $y \le 0$, so $Y$ is uniform(0, 1).
The third equality deserves attention:
- If $F_X$ is strictly increasing, $F_X^{-1}(F_X(x)) = x$.
- If $F_X$ is flat on $[x_1, x_2]$, then $F_X^{-1}(F_X(x)) = x_1$ for any $x$ in that interval, which is not $x$.
- But the probability equality still holds, because $P(X \le x) = P(X \le x_1)$ for any $x \in [x_1, x_2]$. The flat part of the cdf has probability 0: $P(x_1 < X \le x) = F_X(x) - F_X(x_1) = 0$. $\square$
Application: simulation. To generate an observation $X$ with cdf $F_X$:
- generate a uniform(0, 1) random number $V$;
- solve $F_X(x) = V$ for $x$, that is, set $X = F_X^{-1}(V)$.
For example, by Example 2.1.4, $-\log V$ has the exponential distribution with $F(y) = 1 - e^{-y}$.
- This “inverse cdf method” is how computers sample from many distributions.
- It also gives a concrete answer to Theorem 1.5.3’s claim that every cdf belongs to some random variable.
6. Expected values
The expected value, or expectation, of a random variable is its average value, where “average” is weighted according to the probability distribution. It is a measure of center.
Definition 2.2.1. The expected value or mean of a random variable $g(X)$, denoted by $\mathrm{E}\,g(X)$, is
\[\mathrm{E}\,g(X) = \begin{cases} \displaystyle\int_{-\infty}^{\infty} g(x) f_X(x)\, dx & \text{if } X \text{ is continuous} \\[2ex] \displaystyle\sum_{x \in \mathcal{X}} g(x) f_X(x) = \sum_{x \in \mathcal{X}} g(x) P(X = x) & \text{if } X \text{ is discrete,} \end{cases}\]provided that the integral or sum exists. If $\mathrm{E}\lvert g(X) \rvert = \infty$, we say that $\mathrm{E}\,g(X)$ does not exist.
Notice that we compute $\mathrm{E}\,g(X)$ using the distribution of $X$, without first finding the distribution of $g(X)$. (Ross 1988 calls this the “law of the unconscious statistician”; C&B “do not find this amusing.”)
Example 2.2.2 (Exponential mean). Suppose $X$ has an exponential($\lambda$) distribution, with pdf
\[f_X(x) = \frac{1}{\lambda} e^{-x/\lambda}, \quad 0 \le x < \infty, \quad \lambda > 0.\]Then, integrating by parts,
\[\begin{aligned} \mathrm{E}X &= \int_0^{\infty} \frac{1}{\lambda} x e^{-x/\lambda}\, dx \\ &= -x e^{-x/\lambda} \Big|_0^{\infty} + \int_0^{\infty} e^{-x/\lambda}\, dx \\ &= \int_0^{\infty} e^{-x/\lambda}\, dx = \lambda. \end{aligned}\]Example 2.2.3 (Binomial mean). If $X \sim$ binomial($n$, $p$) as in (2.1.3), then (the $x = 0$ term is 0)
\[\mathrm{E}X = \sum_{x=0}^{n} x \binom{n}{x} p^x (1-p)^{n-x} = \sum_{x=1}^{n} x \binom{n}{x} p^x (1-p)^{n-x}.\]Using the identity $x \binom{n}{x} = n \binom{n-1}{x-1}$ and substituting $y = x - 1$,
\[\begin{aligned} \mathrm{E}X &= \sum_{x=1}^{n} n \binom{n-1}{x-1} p^x (1-p)^{n-x} \\ &= np \sum_{y=0}^{n-1} \binom{n-1}{y} p^y (1-p)^{n-1-y} = np, \end{aligned}\]since the last sum is the total of a binomial($n - 1$, $p$) pmf, which is 1. (Trick worth remembering: factor out constants until what remains is a pmf or pdf that sums or integrates to 1.)
Example 2.2.4 (Cauchy mean). A classic random variable whose expected value does not exist is a Cauchy random variable, with pdf
\[f_X(x) = \frac{1}{\pi} \frac{1}{1 + x^2}, \quad -\infty < x < \infty.\]It is straightforward to check that $\int_{-\infty}^{\infty} f_X(x)\, dx = 1$, but $\mathrm{E}\lvert X \rvert = \infty$. For any positive number $M$,
\[\int_0^M \frac{x}{1 + x^2}\, dx = \frac{\log(1 + x^2)}{2} \Big|_0^M = \frac{\log(1 + M^2)}{2},\]so
\[\begin{aligned} \mathrm{E}\lvert X \rvert &= \int_{-\infty}^{\infty} \frac{\lvert x \rvert}{\pi} \frac{1}{1 + x^2}\, dx = \frac{2}{\pi} \int_0^{\infty} \frac{x}{1 + x^2}\, dx \\ &= \lim_{M \to \infty} \frac{1}{\pi} \log(1 + M^2) = \infty, \end{aligned}\]and $\mathrm{E}X$ does not exist.
- The density is symmetric about 0, but “the positive and negative parts cancel” is not allowed.
- Both parts are infinite, and $\infty - \infty$ is undefined.
7. Properties of expectation
Taking expectations is a linear operation: for any constants $a$ and $b$,
\[\mathrm{E}(aX + b) = a\,\mathrm{E}X + b. \tag{2.2.1}\]For example, if $X \sim$ binomial($n$, $p$), then $\mathrm{E}(X - np) = \mathrm{E}X - np = 0$.
Theorem 2.2.5. Let $X$ be a random variable and let $a$, $b$, and $c$ be constants. Then for any functions $g_1(x)$ and $g_2(x)$ whose expectations exist,
- a. $\mathrm{E}\big( a g_1(X) + b g_2(X) + c \big) = a\,\mathrm{E}\,g_1(X) + b\,\mathrm{E}\,g_2(X) + c$.
- b. If $g_1(x) \ge 0$ for all $x$, then $\mathrm{E}\,g_1(X) \ge 0$.
- c. If $g_1(x) \ge g_2(x)$ for all $x$, then $\mathrm{E}\,g_1(X) \ge \mathrm{E}\,g_2(X)$.
- d. If $a \le g_1(x) \le b$ for all $x$, then $a \le \mathrm{E}\,g_1(X) \le b$.
Proof of (a), continuous case. By the additivity of the integral, and since constants factor out,
\[\begin{aligned} \mathrm{E}\big( a g_1(X) + b g_2(X) + c \big) &= \int_{-\infty}^{\infty} \big( a g_1(x) + b g_2(x) + c \big) f_X(x)\, dx \\ &= a \int_{-\infty}^{\infty} g_1(x) f_X(x)\, dx + b \int_{-\infty}^{\infty} g_2(x) f_X(x)\, dx \\ &\qquad + c \int_{-\infty}^{\infty} f_X(x)\, dx, \end{aligned}\]which is $a\,\mathrm{E}\,g_1(X) + b\,\mathrm{E}\,g_2(X) + c$. The discrete case and parts (b)–(d) are similar. $\square$
Caution. Linearity does not extend to nonlinear functions: in general $\mathrm{E}\,g(X) \ne g(\mathrm{E}X)$. For example, if $X \sim$ uniform(0, 1), then $\mathrm{E}X^2 = 1/3 \ne (\mathrm{E}X)^2 = 1/4$.
Example 2.2.6 (Minimizing distance). Measure the distance between $X$ and a constant $b$ by $(X - b)^2$. Which $b$ minimizes $\mathrm{E}(X - b)^2$? (Minimizing $(X - b)^2$ itself is useless, since the answer would depend on $X$.) Adding and subtracting $\mathrm{E}X$,
\[\begin{aligned} \mathrm{E}(X - b)^2 &= \mathrm{E}(X - \mathrm{E}X + \mathrm{E}X - b)^2 \\ &= \mathrm{E}\big( (X - \mathrm{E}X) + (\mathrm{E}X - b) \big)^2 \\ &= \mathrm{E}(X - \mathrm{E}X)^2 + (\mathrm{E}X - b)^2 + 2\,\mathrm{E}\big( (X - \mathrm{E}X)(\mathrm{E}X - b) \big). \end{aligned}\]The last term is $(\mathrm{E}X - b)\,\mathrm{E}(X - \mathrm{E}X) = (\mathrm{E}X - b)(\mathrm{E}X - \mathrm{E}X) = 0$, because $\mathrm{E}X - b$ is a constant. So
\[\mathrm{E}(X - b)^2 = \mathrm{E}(X - \mathrm{E}X)^2 + (\mathrm{E}X - b)^2. \tag{2.2.2}\]- We cannot control the first term.
- The second term is $\ge 0$, with equality when $b = \mathrm{E}X$.
Hence
\[\min_b \mathrm{E}(X - b)^2 = \mathrm{E}(X - \mathrm{E}X)^2. \tag{2.2.3}\]- $\mathrm{E}X$ is the best constant predictor of $X$ under squared error.
- Exercise 2.19 gives a calculus proof; Exercise 2.18 gives the analogous result for the median under absolute error.
- The minimum value, $\mathrm{E}(X - \mathrm{E}X)^2$, is the variance, which starts next week.
Two ways to compute $\mathrm{E}\,g(X)$.
-
Directly from the definition:
\[\mathrm{E}\,g(X) = \int_{-\infty}^{\infty} g(x) f_X(x)\, dx. \tag{2.2.4}\] -
By first finding the pdf $f_Y$ of $Y = g(X)$ (Section 2.1), and then
\[\mathrm{E}\,g(X) = \mathrm{E}Y = \int_{-\infty}^{\infty} y f_Y(y)\, dy. \tag{2.2.5}\]
Example 2.2.7 (Uniform-exponential relationship–II). Let $X \sim$ uniform(0, 1), with $f_X(x) = 1$ if $0 \le x \le 1$ and $0$ otherwise, and let $g(X) = -\log X$. By (2.2.4),
\[\mathrm{E}\,g(X) = \mathrm{E}(-\log X) = \int_0^1 -\log x\, dx = \big( x - x \log x \big) \Big|_0^1 = 1.\]Alternatively, by (2.2.5):
- By Example 2.1.4, $Y = -\log X$ has cdf $1 - e^{-y}$.
- Hence its pdf is $f_Y(y) = \frac{d}{dy}(1 - e^{-y}) = e^{-y}$, $0 < y < \infty$, the exponential pdf with $\lambda = 1$.
- So by Example 2.2.2, $\mathrm{E}Y = 1$, the same answer.
Check your understanding.
-
Let $X$ have pmf $P(X = -1) = 0.2$, $P(X = 0) = 0.5$, $P(X = 2) = 0.3$. Find $\mathrm{E}X$, $\mathrm{E}X^2$, and $\mathrm{E}(3X - 1)$. Is $\mathrm{E}X^2 = (\mathrm{E}X)^2$?
Show answer
$\mathrm{E}X = -0.2 + 0 + 0.6 = 0.4$. $\mathrm{E}X^2 = 0.2 + 0 + 1.2 = 1.4$. $\mathrm{E}(3X - 1) = 3(0.4) - 1 = 0.2$ by (2.2.1). $\mathrm{E}X^2 = 1.4 \ne 0.16 = (\mathrm{E}X)^2$.
-
Let $X$ be continuous with cdf $F_X$. What is the distribution of $1 - F_X(X)$? Use this to explain why $\mathrm{E}F_X(X) = 1/2$.
Show answer
By Theorem 2.1.10, $U = F_X(X) \sim$ uniform(0, 1). Then $1 - U$ is also uniform(0, 1) (Check your understanding 2 of Lecture 4.1 with $a = -1$, $b = 1$). And $\mathrm{E}F_X(X) = \mathrm{E}U = \int_0^1 u\, du = 1/2$.
-
Does the expected value of the pdf $f(x) = 1/x^2$, $1 < x < \infty$, exist?
Show answer
$f$ is a pdf: $\int_1^{\infty} x^{-2}\, dx = 1$. But $\mathrm{E}X = \int_1^{\infty} x \cdot x^{-2}\, dx = \int_1^{\infty} \frac{dx}{x} = \infty$, so the mean does not exist (here it is $+\infty$, since $X > 0$). Heavy tails can make the mean infinite, as in the Cauchy example.
Summary of Week 4
- Functions of a random variable: $P(Y \in A) = P(X \in g^{-1}(A))$ (2.1.2). Discrete case: add $f_X(x)$ over $x \in g^{-1}(y)$.
- Cdf method: $F_Y(y) = P(g(X) \le y)$; identify the $x$-set, then differentiate. Keep track of the supports $\mathcal{X}$ and $\mathcal{Y}$ (2.1.7).
- Monotone $g$: $F_Y(y) = F_X(g^{-1}(y))$ or $1 - F_X(g^{-1}(y))$ (Theorem 2.1.3), and $f_Y(y) = f_X(g^{-1}(y)) \left\lvert \frac{d}{dy} g^{-1}(y) \right\rvert$ (Theorem 2.1.5). Piecewise monotone: sum over the pieces (Theorem 2.1.8).
- Probability integral transformation: $F_X(X) \sim$ uniform(0, 1) for continuous $F_X$; conversely, $F_X^{-1}(V)$ with $V \sim$ uniform(0, 1) has cdf $F_X$.
- Expectation: $\mathrm{E}\,g(X) = \int g(x) f_X(x)\, dx$ or $\sum g(x) f_X(x)$, if $\mathrm{E}\lvert g(X) \rvert < \infty$; it may not exist (Cauchy). It is linear (Theorem 2.2.5), but $\mathrm{E}\,g(X) \ne g(\mathrm{E}X)$ in general. $\mathrm{E}X$ minimizes $\mathrm{E}(X - b)^2$.
Practice Problems
From C&B §2.5:
- Transformations (discrete and monotone): 2.1, 2.2, 2.3.
- Piecewise-monotone transformations: 2.5, 2.6, 2.7.
- Inverse cdfs and the probability integral transformation: 2.8, 2.9, 2.10.
- Expected values: 2.11, 2.12, 2.13, 2.14, 2.15, 2.17, 2.18, 2.19, 2.20.
Next week: moments and moment generating functions; differentiating under an integral sign (§§2.3–2.4).