Tutorials › Measure Theory › Computing Expectation from a Probability Law

Expectation, Conditional Expectation and Independence · Tutorial 743 of 798

Computing Expectation from a Probability Law

Learn to compute expectations directly from discrete probability masses or a density, and determine when an expectation is finite or infinite.

Advanced 10 min read

What You'll Learn

  • Define the push-forward probability law of a real-valued random variable.
  • Derive the expectation formula for nonnegative Borel functions from simple functions.
  • Compute expectations under countable discrete laws, including an infinite sum.
  • Use a Lebesgue density to calculate expectations of transformed random variables.
  • Recognize when a nonnegative expectation is infinite.
  • Distinguish a density calculation from an incorrect sum over point probabilities.

Expectation Depends on the Law

Once the probability law of a random variable is known, its expectation can be computed without returning to the underlying sample space. The key is to integrate the function of interest against that law. For a discrete law this becomes a weighted sum; when the law has a density, it becomes an integral against the density. Either formula may give \(+\infty\) for a nonnegative random variable.

Let \((\Omega,\mathcal{F},\mathbb{P})\) be a probability space, so \(\mathbb{P}(\Omega)=1\), and let \(X:\Omega\to\mathbb{R}\) be a real-valued random variable, meaning an \(\mathcal{F}\)-to-\(\mathcal{B}_{\mathbb{R}}\) measurable function. Its probability law, also called its distribution, is the measure \(\mu_X\) on \((\mathbb{R},\mathcal{B}_{\mathbb{R}})\) defined by \(\mu_X(B)=\mathbb{P}(X\in B)\) for every Borel set \(B\). This is a probability measure. If \(g:\mathbb{R}\to[0,\infty]\) is Borel measurable, then \(g(X)\) is nonnegative and measurable, and its expectation is allowed to be infinite.

Theorem (Expectation from the law): For a probability space \((\Omega,\mathcal{F},\mathbb{P})\), a real-valued random variable \(X\), its law \(\mu_X\), and a nonnegative Borel function \(g:\mathbb{R}\to[0,\infty]\), $$ \mathbb{E}[g(X)]=\int_{\Omega}g(X(\omega))\,d\mathbb{P}(\omega)=\int_{\mathbb{R}}g(x)\,d\mu_X(x), $$ with \(+\infty\) allowed. If \(g\) is real-valued and \(\int_{\mathbb{R}}|g|\,d\mu_X<\infty\), the same identity holds for the finite signed integrals.

Proof. First take \(g=\chi_B\) for a Borel set \(B\subseteq\mathbb{R}\). By the definition of \(\mu_X\), \(\int_{\Omega}\chi_B(X)\,d\mathbb{P}=\mathbb{P}(X\in B)=\mu_X(B)=\int_{\mathbb{R}}\chi_B\,d\mu_X\). Additivity of the integral gives the identity for every nonnegative simple Borel function, by writing it as a finite sum of nonnegative multiples of indicators of disjoint Borel sets.

Now let \(g:\mathbb{R}\to[0,\infty]\) be Borel measurable. There are nonnegative simple Borel functions \(s_n\) increasing pointwise to \(g\); for example, \(s_n=2^{-n}\lfloor 2^n\min(g,n)\rfloor\), where \(\min(+\infty,n)=n\). Each \(s_n\) has finite range, and refinement of the dyadic mesh together with increasing truncation gives \(s_n\le s_{n+1}\); also \(s_n(x)\to g(x)\) at every \(x\). The simple-function identity applies to each \(s_n\). The Monotone Convergence Theorem applies on both measure spaces, since \(s_n\uparrow g\) and \(s_n(X)\uparrow g(X)\), so taking limits in the two simple-function integrals proves the nonnegative formula. For real \(g\) with \(\int |g|\,d\mu_X<\infty\), apply the nonnegative formula to \(g^+\) and \(g^-\), both of which have finite integrals, and subtract. \(\square\)

The theorem says that the distribution contains all the information needed for these expectations: if two real-valued random variables have the same law, then every nonnegative Borel function of them has the same expectation, including when that value is infinite. A probability law need not have a density, and a density need not exist for an arbitrary law.

Discrete Laws: Weighted Sums

Suppose \(\mu_X\) is concentrated on distinct points \(x_1,x_2,\ldots\), with probabilities \(p_j=\mathbb{P}(X=x_j)\). Thus \(p_j\ge0\) and \(\sum_jp_j=1\). For nonnegative Borel \(g\), the expectation formula becomes \(\mathbb{E}[g(X)]=\sum_j g(x_j)p_j\), with the sum of nonnegative terms allowed to be infinite. This is an integral against the atomic law, not an assumption that all laws are discrete.

Worked Example: A Countably Supported Law

Let \(X\) take values \(n=1,2,\ldots\) with \(\mathbb{P}(X=n)=2^{-n}\). Compute \(\mathbb{E}[X]\).

First check that the stated masses define a probability law: \(\sum_{n=1}^{\infty}2^{-n}=(1/2)/(1-1/2)=1\). The law formula gives \(\mathbb{E}[X]=\sum_{n=1}^{\infty}n2^{-n}\). For a finite partial sum, multiplying by \(1/2\) and subtracting yields \[ \frac12\sum_{n=1}^N\frac{n}{2^n} =\sum_{n=1}^N\frac{n}{2^{n+1}} =\sum_{n=1}^N\frac{n-1}{2^n}+\frac{N}{2^{N+1}}, \] or, equivalently, the finite geometric-sum calculation gives \[ \sum_{n=1}^N\frac{n}{2^n}=2-\frac{N+2}{2^N}. \] (The latter identity also follows by induction: it is \(1/2\) at \(N=1\), and adding \((N+1)/2^{N+1}\) gives the formula at \(N+1\).) Since \((N+2)/2^N\to0\), the nonnegative series sums to \(2\), so \(\mathbb{E}[X]=2\). Check: at \(N=3\), the partial sum is \(1/2+2/4+3/8=11/8\); the formula gives \(2-5/8=11/8\). The finite sums increase toward the computed limit.

For a finite law, the same rule is a finite weighted sum. In particular, the weights must be the probabilities of the values, and values with probability zero contribute zero. No limiting argument is needed in that case.

Worked Example: Computing an Expectation Under a Finite Law

Suppose \(\mathbb{P}(X=-1)=1/4\), \(\mathbb{P}(X=0)=1/2\), and \(\mathbb{P}(X=2)=1/4\). Compute \(\mathbb{E}[X]\) and \(\mathbb{E}[X^2]\).

The probabilities sum to \(1/4+1/2+1/4=1\). Applying the discrete formula to \(g(x)=x\) gives \[ \mathbb{E}[X]=(-1)\left(\frac14\right)+0\left(\frac12\right)+2\left(\frac14\right) =-\frac14+0+\frac12=\frac14. \] For \(g(x)=x^2\), \[ \mathbb{E}[X^2]=(-1)^2\left(\frac14\right)+0^2\left(\frac12\right)+2^2\left(\frac14\right) =\frac14+0+1=\frac54. \] Check: the squared values are \(1,0,4\), and weighting them by the same probabilities gives \(1/4+0+4/4=5/4\), as above. The two expectations differ because the functions \(x\) and \(x^2\) assign different values to each outcome.

Absolutely Continuous Laws: Integrating Against a Density

Suppose the law \(\mu_X\) is absolutely continuous with respect to Lebesgue measure \(m\) on \(\mathbb{R}\), with density \(f_X\). This means \(f_X:\mathbb{R}\to[0,\infty]\) is Lebesgue measurable and \(\mu_X(B)=\int_B f_X\,dm\) for every Borel set \(B\). In particular, \(\int_{\mathbb{R}} f_X\,dm=1\). The density formula follows by integrating against this law: \[ \mathbb{E}[g(X)]=\int_{\mathbb{R}}g(x)f_X(x)\,dm(x) \] for nonnegative Borel \(g\), with \(+\infty\) allowed. For signed \(g\), this is a finite expectation when \(\int_{\mathbb{R}}|g(x)|f_X(x)\,dm(x)<\infty\). Values of a density on a Lebesgue null set do not affect these integrals.

Worked Example: A Uniform Density on a Bounded Interval

Let \(X\) have density \(f_X(x)=1/2\) for \(0\le x\le2\), and \(f_X(x)=0\) otherwise. Compute \(\mathbb{E}[X]\) and \(\mathbb{E}[X^2]\).

The density is nonnegative, and its integral is \(\int_0^2(1/2)\,dx=1\), as required for a probability law. Using \(g(x)=x\), \[ \mathbb{E}[X]=\int_0^2 x\frac12\,dx =\frac12\left[\frac{x^2}{2}\right]_0^2 =\frac12(2-0)=1. \] Using \(g(x)=x^2\), \[ \mathbb{E}[X^2]=\int_0^2 x^2\frac12\,dx =\frac12\left[\frac{x^3}{3}\right]_0^2 =\frac12\left(\frac83-0\right)=\frac43. \] Both are finite because the integrands are bounded on an interval of finite measure. Check: changing variables \(x=2u\) in the second integral gives \(\int_0^1 (2u)^2\,du=4[u^3/3]_0^1=4/3\), the same value.

The same method applies when \(g\) is a transformation, rather than the identity function. For example, to compute \(\mathbb{E}[X^2]\) from a density, integrate \(x^2 f_X(x)\), not merely \(x f_X(x)\). The law formula is for a Borel function of \(X\), so the integrand is the chosen function multiplied by the density.

Worked Example: An Exponential Density

Let \(X\) have density \(f_X(x)=e^{-x}\) for \(x\ge0\), and \(f_X(x)=0\) for \(x<0\). Compute \(\mathbb{E}[X]\).

The density has total integral \(\int_0^\infty e^{-x}\,dx=[-e^{-x}]_0^\infty=1\). The expectation is nonnegative and is given by \[ \mathbb{E}[X]=\int_0^\infty xe^{-x}\,dx. \] For \(R>0\), integration by parts gives \[ \int_0^R xe^{-x}\,dx =\left[-xe^{-x}\right]_0^R+\int_0^R e^{-x}\,dx = -Re^{-R}+1-e^{-R} =1-(R+1)e^{-R}. \] As \(R\to\infty\), \((R+1)e^{-R}\to0\), so the integral over \([0,\infty)\), defined as the increasing limit of these integrals, equals \(1\). Thus \(\mathbb{E}[X]=1\). Check: the truncated integrals are \(1-(R+1)e^{-R}\), which are below \(1\) and approach \(1\), consistent with integrating a nonnegative function.

When the Expectation Is Infinite

For nonnegative \(g(X)\), the expectation is always defined as a value in \([0,\infty]\). It is not guaranteed to be finite just because the law is a probability measure. A density can integrate to \(1\) while its product with \(x\) has a divergent integral. The next example checks both facts separately.

Worked Example: A Probability Density with Infinite Mean

Let \(X\) have density \(f_X(x)=1/x^2\) for \(x\ge1\), and \(f_X(x)=0\) for \(x<1\). Determine whether its expectation is finite.

First verify that this is a probability density: \[ \int_1^\infty \frac{1}{x^2}\,dx =\lim_{R\to\infty}\left[-\frac1x\right]_1^R =\lim_{R\to\infty}\left(1-\frac1R\right)=1. \] For the nonnegative function \(g(x)=x\), the density formula gives \[ \mathbb{E}[X]=\int_1^\infty x\frac{1}{x^2}\,dx =\int_1^\infty \frac1x\,dx. \] For every integer \(k\ge0\), the contribution on \([2^k,2^{k+1}]\) is \[ \int_{2^k}^{2^{k+1}}\frac1x\,dx =\ln(2^{k+1})-\ln(2^k)=\ln 2. \] These intervals have disjoint interiors, and each contributes the same positive amount. Therefore the integrals over \([1,2^N]\) equal \(N\ln2\), which tends to \(+\infty\); hence \(\mathbb{E}[X]=+\infty\). Check: the density tail integral from \(R\) to infinity is \(1/R\), which tends to zero, so the law has total mass \(1\); this does not make the mean finite, since the mean’s integral has the divergent contribution just computed.

A Common Mistake: Treating a Density as Point Probabilities

For a law with a Lebesgue density, probabilities of individual points are zero: for every \(a\in\mathbb{R}\), \(\mu_X(\{a\})=\int_{\{a\}}f_X\,dm=0\), because a singleton has Lebesgue measure zero. It is therefore incorrect to try to compute a continuous expectation by summing \(x\,\mathbb{P}(X=x)\) over individual points.

For a concrete correction, let \(X\) be uniform on \([0,1]\), with density \(f_X(x)=1\) there and \(0\) elsewhere. The incorrect point-mass calculation would give zero contributions at every point, since \(\mathbb{P}(X=x)=0\). But the density formula gives \[ \mathbb{E}[X]=\int_0^1 x\,dx=\left[\frac{x^2}{2}\right]_0^1=\frac12. \] Indeed, the probability is distributed across intervals, not assigned as positive mass to any one point. Discrete sums apply to atomic laws; density integrals apply to absolutely continuous laws.

The practical choice is determined by the law: sum over atoms for a discrete distribution, and integrate against a density when the law has one. In either case, first identify the function whose expectation is requested, then apply the law formula to that function. For nonnegative functions, the answer may be infinite; for a signed function, the usual finite expectation requires integrability of its absolute value.

Check Your Understanding

For each question, identify the law being used and check whether the expectation is finite before reporting a finite value.

  1. A random variable takes values \(0,1,3\) with probabilities \(1/2,1/3,1/6\). Compute \(\mathbb{E}[X]\) and \(\mathbb{E}[X^2]\).
  2. If \(\mathbb{P}(X=n)=3^{-n}/\sum_{k=1}^{\infty}3^{-k}\) for \(n\ge1\), write the law formula for \(\mathbb{E}[X]\) and determine whether the defining series converges.
  3. A random variable has density \(f_X(x)=2x\) on \([0,1]\) and zero elsewhere. Verify the density is normalized and compute \(\mathbb{E}[X]\).
  4. For the density \(f_X(x)=1/x^2\) on \([1,\infty)\), compute \(\mathbb{E}[X^q]\) for \(0<q<1\). Which step differs from the mean calculation?
  5. Explain why the formula \(\sum_x x\,\mathbb{P}(X=x)\) cannot compute the expectation of a random variable with a uniform law on \([0,1]\).