Tutorials › Statistical Theory I - Probability and Distribution Theory › Expectation from a Probability Density

Expectation and LOTUS · Tutorial 299 of 994

Expectation from a Probability Density

Learn to compute a density-based expectation by integrating over the distribution’s support and checking that the required integral is finite.

Intermediate 9 min read

What You'll Learn

  • Define expectation from a probability density and state when the integral is finite.
  • Choose the correct integration region from a density’s support.
  • Compute expectations on bounded intervals, half-lines, and the real line.
  • Evaluate uniform and exponential expectations by direct integration.
  • Use symmetry to compute the expectation of a normal random variable.
  • Check integrability and avoid incorrect cancellation of divergent integrals.

From a Density to an Average

For a discrete random variable, expectation is obtained by weighting each possible value by its probability and adding the results. A density describes probability differently: probabilities are accumulated over intervals by integration. The corresponding average is therefore an integral in which each possible value \(x\) is weighted by its density \(f(x)\).

The key practical question is not just how to integrate, but where to integrate. A density may be zero outside a bounded interval, on a half-line, or nowhere on the real line. The limits must match the region where the density carries probability. For unbounded regions, the integral must also converge in the appropriate sense.

Definition: Suppose \(X\) has a probability density \(f\) on the real line, so \(f(x)\geq 0\) and \(\int_{-\infty}^{\infty} f(x)\,dx=1\). If \(\int_{-\infty}^{\infty} |x|f(x)\,dx<\infty\), the expectation of \(X\) is \[ E[X]=\int_{-\infty}^{\infty} x f(x)\,dx. \] If \(f(x)=0\) outside a region \(S\), up to sets of length zero, the same expectation can be written as \(\int_S x f(x)\,dx\). In an unbounded region, the absolute-integrability condition ensures this integral is finite and does not depend on cancellation between divergent parts.

A density is defined up to changes on sets of length zero. Consequently, including or excluding an endpoint from the integration region does not change an expectation. In computations, it is usually clearest to integrate over the interval or intervals on which the displayed density is positive. If the density is given piecewise, split the integral at the points where its formula changes.

The condition \(\int |x|f(x)\,dx<\infty\) is automatic for a density supported on a bounded interval: there, \(|x|\) is bounded. For unbounded support, it must be checked or established by the calculation. In particular, one cannot infer a finite expectation merely because positive and negative contributions appear to cancel.

Expectation on a Bounded Support

On a bounded interval, expectation is a weighted average of values in that interval. The density supplies the weights, and its total integral is one. The following result makes the range of this average precise.

Theorem: If a probability density \(f\) is zero outside \([a,b]\), where \(a\leq b\) are finite, then \(E[X]\) exists and \(a\leq E[X]\leq b\).

Proof. On \([a,b]\), \(|x|\leq \max(|a|,|b|)\), so \[ \int_a^b |x|f(x)\,dx\leq \max(|a|,|b|)\int_a^b f(x)\,dx=\max(|a|,|b|)<\infty. \] Thus the expectation is finite. Since \(x-a\geq 0\) and \(b-x\geq 0\) throughout the interval, and \(f(x)\geq 0\), \[ \int_a^b (x-a)f(x)\,dx\geq 0, \qquad \int_a^b (b-x)f(x)\,dx\geq 0. \] Using \(\int_a^b f(x)\,dx=1\), these inequalities become \(E[X]-a\geq 0\) and \(b-E[X]\geq 0\). Hence \(a\leq E[X]\leq b\). \(\square\)

Worked Example: A Uniform Density on a Bounded Interval

Let \(X\) have the uniform distribution on \([2,6]\), with density \(f(x)=1/4\) for \(2\leq x\leq 6\) and zero elsewhere. Find \(E[X]\).

The density is zero outside \([2,6]\), so integrate over that interval:

$$ E[X]=\int_2^6 x\frac14\,dx =\frac14\left[\frac{x^2}{2}\right]_2^6 =\frac18(36-4) =4. $$

The density is normalized, since \(\int_2^6 (1/4)\,dx=1\). The result \(4\) lies between the support endpoints \(2\) and \(6\), as the theorem requires.

The same procedure applies when a bounded density is not constant. Integrate \(x f(x)\) over each piece of the support, using the appropriate formula for \(f\) on that piece. The density values do not themselves describe the average; the integrand is the value \(x\) multiplied by its density \(f(x)\).

Expectation on Unbounded Supports

For a density supported on a half-line or on all of \(\mathbb{R}\), the expectation integral is an improper integral. Its convergence must be justified. If the support is \([0,\infty)\), for example, absolute integrability requires \(\int_0^\infty x f(x)\,dx<\infty\). For a density on the whole real line, the relevant check is \(\int_{-\infty}^{\infty}|x|f(x)\,dx<\infty\).

For an absolutely integrable integrand, the usual improper-integral calculation is legitimate: compute over finite intervals and take the relevant limits. When the support extends in both directions, one can check the two tails separately. Absolute integrability means their absolute contributions have a finite sum.

Worked Example: The Mean of an Exponential Distribution

Let \(X\) have an exponential density with rate \(\lambda=2\): \(f(x)=2e^{-2x}\) for \(x\geq 0\), and \(f(x)=0\) for \(x<0\). Find \(E[X]\), checking that the expectation is finite.

The support is \([0,\infty)\). First, the density is normalized: \(\int_0^\infty 2e^{-2x}\,dx=1\). Since \(x\geq 0\), the absolute-integrability check is the same as computing the expectation integral. On \([0,R]\), integration by parts with \(u=x\) and \(dv=2e^{-2x}\,dx\) gives

$$ \int_0^R 2xe^{-2x}\,dx =\left[-xe^{-2x}\right]_0^R+\int_0^R e^{-2x}\,dx =-Re^{-2R}+\frac{1-e^{-2R}}{2}. $$

As \(R\to\infty\), \(e^{-2R}\to 0\) and \(Re^{-2R}\to 0\). Therefore the integral converges to \(1/2\), proving both finiteness and

$$ E[X]=\int_0^\infty x\,2e^{-2x}\,dx=\frac12. $$

The support is unbounded above, but the density decreases quickly enough that the integral of \(x f(x)\) is finite.

For a density on the whole real line, the value of \(x\) may be negative as well as positive. A useful symmetry calculation is available when the density is symmetric about zero.

Theorem: Suppose \(f\) is a probability density satisfying \(f(-x)=f(x)\) for almost every \(x\), and \(\int_{-\infty}^{\infty}|x|f(x)\,dx<\infty\). Then \(E[X]=0\).

Proof. Absolute integrability permits splitting the integral at zero and changing variables in the negative half. In the negative half, set \(u=-x\), so \(x=-u\), \(dx=-du\), and the limits \(x=-\infty,0\) become \(u=\infty,0\). Thus

$$ \int_{-\infty}^{0} x f(x)\,dx =\int_{\infty}^{0}(-u)f(-u)(-du) =-\int_0^\infty u f(u)\,du. $$

The positive-half integral is \(\int_0^\infty u f(u)\,du\). Adding the two finite contributions gives \(E[X]=0\). \(\square\)

Worked Example: The Mean of a Normal Distribution

Let \(X\sim N(\mu,\sigma^2)\), where \(\mu\in\mathbb{R}\) and \(\sigma>0\). Its density is \(f(x)=\frac{1}{\sigma\sqrt{2\pi}}\exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)\) for all real \(x\). Find its expectation by integrating over the full support.

Put \(z=(x-\mu)/\sigma\), so \(x=\mu+\sigma z\) and \(dx=\sigma\,dz\). The density times \(dx\) becomes \(\phi(z)\,dz\), where \(\phi(z)=\frac{1}{\sqrt{2\pi}}e^{-z^2/2}\). Hence

$$ E[X]=\int_{-\infty}^{\infty}x f(x)\,dx =\int_{-\infty}^{\infty}(\mu+\sigma z)\phi(z)\,dz =\mu\int_{-\infty}^{\infty}\phi(z)\,dz +\sigma\int_{-\infty}^{\infty}z\phi(z)\,dz. $$

The first integral is \(1\), because \(\phi\) is a probability density. The second is zero: \(\phi\) is even, so \(z\phi(z)\) is odd, and its absolute integral is finite. Indeed, \(\int_0^\infty z\phi(z)\,dz=1/\sqrt{2\pi}\), as follows by substituting \(v=z^2/2\); the negative half contributes its negative. Therefore \(E[X]=\mu\). This calculation also verifies finiteness: \(|x|\leq |\mu|+\sigma|z|\) after the substitution, and \(\int |z|\phi(z)\,dz<\infty\).

Common Pitfalls and Why the Region Matters

A density formula may be written only on its support, or it may be defined on the entire real line with value zero outside the support. Either way, the expectation integral must account for the region carrying probability. Using incorrect limits can omit probability mass, include points where the density formula does not apply, or produce a result inconsistent with the distribution.

  • Using the density rather than the value-weighted density. The density integrates to one. The expectation integrates \(x f(x)\), not just \(f(x)\).
  • Ignoring the support. For a density supported on \([0,\infty)\), integrate from \(0\) to \(\infty\), not over an arbitrary finite interval. For a density supported on \([a,b]\), integrate over \([a,b]\).
  • Assuming a finite-looking answer proves convergence. On unbounded support, establish that \(\int |x|f(x)\,dx\) is finite. A formal cancellation between positive and negative tails does not establish a finite expectation.
  • Expecting the answer to be a possible value. An expectation is an average and need not be a value with positive probability. It does, however, lie within the bounds of a bounded support.

These calculations are the density-based definition of expectation for \(X\) itself. Integrating a function of \(X\) directly against a density is a related but distinct rule; the immediate task here is to identify the support, form \(x f(x)\), and evaluate its integral under the required finiteness condition.

Key takeaway: For a density \(f\), compute \(E[X]\) as \(\int x f(x)\,dx\) over the region where the density is supported. On bounded support the integral is finite; on unbounded support, check absolute integrability before interpreting the result as a finite expectation.

Check Your Understanding

Use the support and density in each question to set up the expectation integral before evaluating or reasoning about it.

  1. A density is \(1/3\) on \([-1,2]\) and zero elsewhere. Set up and compute \(E[X]\), then check that it lies in the support.
  2. For a density supported on \([0,\infty)\), what integral must be finite for the expectation to exist as a finite value?
  3. Explain why symmetry of a density about zero alone is not enough for the symmetry theorem above unless the absolute-integrability condition also holds.
  4. A density on \([a,b]\) integrates to one. Use nonnegative integrands to show that its expectation cannot be less than \(a\) or greater than \(b\).
  5. For the density \(f(x)=3e^{-3x}\) on \(x\geq 0\), identify the correct integration region for \(E[X]\) and state why it is an improper integral.