Tutorials › VEE Mathematical Statistics › Expectation of a Function of a Random Variable

VEE Mathematical Statistics · Expectation and Variability · Tutorial 62 of 880

Expectation of a Function of a Random Variable

Calculate expected values of functions directly from a PMF or density, and recognize when the method is valid.

Beginner 10 min read

What You'll Learn

  • Apply the direct expectation formula to a discrete PMF.
  • Apply the direct expectation formula to a continuous density.
  • Check that probabilities or density mass sum or integrate to one.
  • Evaluate nonlinear functions without first finding their distributions.
  • Identify the difference between the expectation of a function and the function of an expectation.

Why Evaluate a Function Directly?

A random variable may describe a count, amount, duration, or other outcome, while the quantity of interest is a function of that outcome. For example, a hypothetical service plan might impose a charge that depends quadratically on the number of reported incidents. The charge is determined by the count, but its expected value need not be calculated by first constructing a separate probability distribution for the charge.

The direct method weights the function value at each possible outcome by that outcome’s probability, or integrates function values against a density. It is especially useful when the function is easy to evaluate but the distribution of the transformed variable would be awkward to derive.

Definition: Let \(X\) be a random variable and let \(g\) be a function. The expectation of \(g(X)\), when it exists, is calculated from the distribution of \(X\). If \(X\) is discrete with PMF \(p_X(x)=P(X=x)\), then
$$ E[g(X)]=\sum_x g(x)p_X(x). $$
If \(X\) is continuous with density \(f_X\), then
$$ E[g(X)]=\int_{-\infty}^{\infty}g(x)f_X(x)\,dx. $$
For the expectation to be finite, the corresponding sum of \(|g(x)|p_X(x)\) or integral of \(|g(x)|f_X(x)\) must be finite. If \(g(X)\) is nonnegative, its expectation can instead be infinite.

Applying the Formula to a PMF

For a discrete random variable, list its possible values, evaluate \(g\) at each value, and weight each result by the probability of that value. The sum ranges over the possible values of \(X\), not over a new distribution that must be found for \(g(X)\). If two different values of \(X\) produce the same value of \(g(X)\), both contributions still appear in the sum.

Before calculating, verify that the listed probabilities are nonnegative and add to one. This check confirms that they define a PMF. A function applied to a valid random variable does not repair an invalid probability model.

Worked Example: Expected Charge From a Discrete Count

In a hypothetical quarterly service plan, \(X\) is the number of qualifying incidents reported by one customer. Its PMF is \(P(X=0)=0.10\), \(P(X=1)=0.40\), \(P(X=2)=0.30\), and \(P(X=3)=0.20\). The plan’s hypothetical charge, in dollars, is \(g(X)=20+5X^2\). Find the expected charge.

Method. Apply the discrete expectation formula directly to the charge function. First check the PMF:

$$ 0.10+0.40+0.30+0.20=1.00. $$

The probabilities are nonnegative and sum to one, so the PMF is valid. Evaluate the charge at each possible count:

$$ g(0)=20+5(0)^2=20,\quad g(1)=20+5(1)^2=25, $$ $$ g(2)=20+5(2)^2=40,\quad g(3)=20+5(3)^2=65. $$

Weight each charge by the probability of its count and add:

$$ \begin{aligned} E[g(X)] &=20(0.10)+25(0.40)+40(0.30)+65(0.20)\\ &=2+10+12+13\\ &=37. \end{aligned} $$

The expected hypothetical quarterly charge is $37. As a check, the four weighted contributions sum to $37, and the probabilities used in the calculation sum to one. A common mistake is to average the count first and then apply the quadratic charge function; that generally does not give the average charge. The direct weighted calculation avoids that mistake.

Applying the Formula to a Density

For a continuous random variable, individual point probabilities are generally zero. The density \(f_X(x)\) assigns probability across intervals, and the expectation formula accumulates the function values with density weight over the support. The integral can be restricted to the support, where the density is nonzero.

Check that the density is nonnegative and integrates to one before using it. Then multiply the function by the density, integrate over the support, and evaluate the result. The integrand is \(g(x)f_X(x)\), not just \(g(x)\).

Worked Example: Expected Squared Distance From a Center

Let \(X\) have density \(f_X(x)=x/2\) for \(0\leq x\leq2\), and \(f_X(x)=0\) elsewhere. Find \(E[(X-1)^2]\). This example uses a hypothetical continuous measurement; no particular insurance or mortality assumption is involved.

Method. First verify that the proposed density is normalized and nonnegative. It is nonnegative on its support, and

$$ \int_0^2 \frac{x}{2}\,dx =\left[\frac{x^2}{4}\right]_0^2 =1. $$

Thus this is a valid density. Use \(g(x)=(x-1)^2\) and integrate over the support:

$$ \begin{aligned} E[(X-1)^2] &=\int_0^2 (x-1)^2\frac{x}{2}\,dx\\ &=\frac12\int_0^2 (x^3-2x^2+x)\,dx\\ &=\frac12\left[\frac{x^4}{4}-\frac{2x^3}{3}+\frac{x^2}{2}\right]_0^2\\ &=\frac12\left(4-\frac{16}{3}+2\right)\\ &=\frac12\left(\frac{2}{3}\right)\\ &=\frac13. \end{aligned} $$

Therefore, \(E[(X-1)^2]=1/3\). The density check matters: replacing \(x/2\) with \(x/4\) on this same support would give total probability \(1/2\), not one, and would not define the stated probability distribution.

Why the Direct Formula Holds

The formula is not a shortcut that changes the meaning of expectation. It follows from how expectation weights outcomes. For a discrete variable, the justification is exact: collect together the possible values of \(X\) that lead to the same value of \(g(X)\).

1
Start with the expectation of the transformed variable.
Write \(Y=g(X)\). By the definition of expectation for a discrete variable, \(E[Y]\) is the sum of each possible value \(y\) of \(Y\), multiplied by \(P(Y=y)\).
2
Express each transformed-value probability using \(X\).
The event \(Y=y\) consists of all outcomes \(x\) for which \(g(x)=y\). Therefore \(P(Y=y)=\sum_{x:g(x)=y}p_X(x)\).
3
Regroup the sum by the original outcomes.
Substituting the event probabilities gives \(E[Y]=\sum_y y\sum_{x:g(x)=y}p_X(x)\). Since \(y=g(x)\) within each group, this is \(\sum_x g(x)p_X(x)\), as claimed.

For a continuous variable, the same weighting principle gives the integral formula. To see the idea in a setting with continuous \(g\), bounded support, and a continuous density, divide the support into small intervals. On each interval, approximate \(g(x)\) by its value at a representative point. The expected contribution from that interval is approximately that function value multiplied by the interval’s probability, which is the integral of \(f_X\) over the interval. Summing across intervals gives an approximation to \(\int g(x)f_X(x)\,dx\); as the intervals become narrower, the approximation converges to that integral. The formula also holds under the stated integrability condition more generally.

Theorem: For a function \(g\), calculate \(E[g(X)]\) from the PMF or density of \(X\): sum \(g(x)\) times the PMF for a discrete variable, or integrate \(g(x)\) times the density for a continuous variable. This does not require \(g\) to be one-to-one.

Worked Example: A Nonlinear Function Under a Continuous Density

Worked Example: Average Reciprocal Factor

A hypothetical process has a duration \(X\), in hours, with uniform distribution on \([0,3]\). Thus \(f_X(x)=1/3\) for \(0\leq x\leq3\) and zero elsewhere. A process score is \(g(X)=1/(1+X)\). Find its expected score, rounded to four decimal places.

Method. The density is nonnegative, and its integral is

$$ \int_0^3 \frac13\,dx=\frac13(3)=1, $$

so it is valid. Apply the direct formula and integrate only over the support:

$$ \begin{aligned} E[g(X)] &=\int_0^3 \frac{1}{1+x}\cdot\frac13\,dx\\ &=\frac13\left[\ln(1+x)\right]_0^3\\ &=\frac13(\ln 4-\ln 1)\\ &=\frac{\ln 4}{3}\\ &\approx 0.4621. \end{aligned} $$

The expected score is \(0.4621\) to four decimal places. The calculation evaluates the reciprocal at each possible duration and weights it by the uniform density; it does not require finding a density for the transformed score. A common mistake is to use an unweighted integral of \(1/(1+x)\). The factor \(1/3\) is essential because it is the density on the support.

Common Exam Traps and Practical Checks

Direct calculation is simple in form, but a few errors can change the answer substantially. Use the following checks before settling on a result:

  • Do not substitute the mean into the function. In general, \(E[g(X)]\) is not \(g(E[X])\). For the density \(f_X(x)=x/2\) on \([0,2]\), \(E[X]=\int_0^2 x(x/2)\,dx=4/3\). Hence \(g(E[X])=(4/3-1)^2=1/9\) for \(g(x)=(x-1)^2\), whereas the direct expectation is \(1/3\).
  • Do not omit the PMF or density weight. A continuous expectation integrates \(g(x)f_X(x)\), not \(g(x)\) alone. A discrete expectation multiplies each function value by its probability.
  • Check the probability model first. A PMF must have nonnegative entries summing to one; a density must be nonnegative and integrate to one. If the check fails, the proposed inputs do not describe the stated probability distribution.
  • Use the support. Integrate only where the density is nonzero, and include every possible value in a discrete sum. Values outside the support have no probability contribution.
  • Retain repeated function values correctly. If different \(x\)-values give the same \(g(x)\), include each of their weighted contributions. Combining them is optional, not necessary.

These steps make the method useful in actuarial settings whenever a random count or amount feeds into a charge, score, or other derived quantity. The expectation remains an average over the original random outcomes, with the PMF or density providing the weights.

Check Your Understanding

For each problem, calculate the requested expectation directly from the given PMF or density.

  1. A discrete variable \(X\) takes values \(-1,0,2\) with probabilities \(0.25,0.50,0.25\), respectively. Find \(E[X^2+1]\). (Answer: \(2.25\))
  2. A continuous variable has density \(f_X(x)=2x/9\) for \(0\leq x\leq3\), and zero elsewhere. Verify the density and find \(E[3-X]\). (Answer: \(1\))
  3. A discrete variable \(X\) takes values \(1,2,4\) with probabilities \(0.20,0.50,0.30\), respectively. Find \(E[1/X]\). (Answer: \(0.525\))
  4. A variable \(X\) is uniform on \([0,4]\). Find \(E[(X-2)^2]\) by integrating against its density. (Answer: \(4/3\))
  5. A variable has density \(f_X(x)=3x^2/8\) for \(0\leq x\leq2\), and zero elsewhere. Verify the density and find \(E[1/(1+X)]\), rounded to four decimal places. (Answer: \(3\ln(3)/8\approx0.4120\))
Clinical Biostats