Skip to content
VidiMaster it, module by module
Module 8/Expectation & Variance

Expectation: The Mean of a Random Variable

The expectation (or mean) of a random variable is the single number that says where its probability is centred — a weighted average of the values, each weighted by its probability. For a discrete variable this is E[X]=∑kk P{X=k}\mathbb{E}[X]=\sum_k k\,\mathbb{P}\{X=k\} (Definition 13.1), also called the first moment and written μ=E[X]\mu=\mathbb{E}[X]; rolling a fair die gives E[X]=16(1+⋯+6)=3.5\mathbb{E}[X]=\tfrac16(1+\cdots+6)=3.5 (Example 13.1) — already a sign that the mean need not be a value XX can actually take. For a continuous variable the sum becomes an integral against the density, E[X]=∫−∞∞x f(x) dx\mathbb{E}[X]=\int_{-\infty}^{\infty} x\,f(x)\,dx (Definition 13.2), which for X∼Unif[a,b]X\sim\mathrm{Unif}[a,b] returns the midpoint a+b2\tfrac{a+b}{2} (Example 13.7). To average a function of XX you do not need the distribution of g(X)g(X): the law of the unconscious statistician (Proposition 13.1) gives E[g(X)]=∑kg(k) P{X=k}\mathbb{E}[g(X)]=\sum_k g(k)\,\mathbb{P}\{X=k\}, and the choice g(x)=xng(x)=x^n produces the moments E[Xn]\mathbb{E}[X^n] (Definition 13.3). Expectation is powerful but not automatic: it is well-defined only when its sum or integral settles on a value, finite or ±∞\pm\infty (Remark 13.1), and it can be infinite (Examples 13.5, 13.8) or even undefined (Example 13.6). (The means of the named distributions — Bernoulli, binomial, geometric — are developed in a later lesson; here we keep them light.)

Before you start — give these a try

Attempting first primes your brain for the lesson — even if you miss. Nothing is graded or saved; it's just a warm-up.

For a discrete random variable XX and a function gg, which formula is the law of the unconscious statistician for E[g(X)]\mathbb{E}[g(X)]?

Let X∼Unif[3,10]X\sim\mathrm{Unif}[3,10]. Find E[X]\mathbb{E}[X]. Give your answer as a decimal to 33 places.

What you’ll be able to do

  • State Definition 13.1: the expectation of a discrete random variable is the weighted average E[X]=∑kk P{X=k}\mathbb{E}[X]=\sum_k k\,\mathbb{P}\{X=k\} (the first moment μ\mu), and compute it for a fair die (E[X]=3.5\mathbb{E}[X]=3.5, Example 13.1) and for small p.m.f.s and payoff games.
  • Apply Definition 13.2, E[X]=∫−∞∞x f(x) dx\mathbb{E}[X]=\int_{-\infty}^{\infty} x\,f(x)\,dx, to average a continuous variable against its density, recovering the uniform mean E[X]=a+b2\mathbb{E}[X]=\tfrac{a+b}{2} for X∼Unif[a,b]X\sim\mathrm{Unif}[a,b] (Example 13.7).
  • Use the law of the unconscious statistician (Proposition 13.1), E[g(X)]=∑kg(k) P{X=k}\mathbb{E}[g(X)]=\sum_k g(k)\,\mathbb{P}\{X=k\}, to compute E[g(X)]\mathbb{E}[g(X)] — such as a second moment E[X2]\mathbb{E}[X^2] — without first finding the distribution of g(X)g(X).
  • Define the moments E[Xn]\mathbb{E}[X^n] of a random variable (Definition 13.3) and recognise the mean as the first moment (n=1n=1).
  • Explain when an expectation is well-defined (Remark 13.1), and recognise that E[X]\mathbb{E}[X] can be a non-attained value, can be infinite (Examples 13.5, 13.8) or undefined (Example 13.6), and — being a mean, not a probability — need not lie in [0,1][0,1].

In your course

· MATH2015 · Linear Algebra & Probability
§13.1 Expectation
  • Definition 13.1Expectation (discrete)
    E[X]=∑kk P{X=k}\mathbb{E}[X]=\sum_k k\,\mathbb{P}\{X=k\}, over all possible values kk; the first moment μ=E[X]\mu=\mathbb{E}[X].
  • Remark 13.1Well-defined expectation
    E[X]\mathbb{E}[X] is well-defined if its sum/integral has a definite value — finite, or +∞+\infty, or −∞-\infty.
  • Example 13.1Mean of a fair die
    E[X]=16(1+2+3+4+5+6)=216=3.5\mathbb{E}[X]=\tfrac16(1+2+3+4+5+6)=\tfrac{21}{6}=3.5.
  • Definition 13.2Expectation (continuous)
    E[X]=∫−∞∞x f(x) dx\mathbb{E}[X]=\int_{-\infty}^{\infty} x\,f(x)\,dx for a density ff.
  • Example 13.7Mean of a uniform variable
    For X∼Unif[a,b]X\sim\mathrm{Unif}[a,b], E[X]=a+b2\mathbb{E}[X]=\dfrac{a+b}{2}.
  • Proposition 13.1Law of the unconscious statistician (LOTUS)
    For discrete XX, E[g(X)]=∑kg(k) P{X=k}\mathbb{E}[g(X)]=\sum_k g(k)\,\mathbb{P}\{X=k\}.
  • Definition 13.3Moments
    The nn-th moment of XX is E[Xn]\mathbb{E}[X^n]; the first moment is the mean.
  • Examples 13.5, 13.6, 13.8Infinite or undefined expectation
    A defining sum/integral can diverge to ∞\infty (Examples 13.5, 13.8) or fail to converge at all (Example 13.6), so E[X]\mathbb{E}[X] may be infinite or undefined.
Examples 13.2–13.4 (the means of the Bernoulli pp, binomial npnp, and geometric 1/p1/p) are kept light here and are developed in the later lesson on moments of the standard distributions.
1

Expectation of a discrete random variable

The expectation (or mean) of a discrete random variable XX is E[X]=∑kk P{X=k},\mathbb{E}[X]=\sum_k k\,\mathbb{P}\{X=k\}, the sum running over every possible value kk of XX (Definition 13.1). It is a weighted average of the outcomes, each value kk weighted by how likely it is, P{X=k}\mathbb{P}\{X=k\}: the more probability sits at a value, the harder it pulls the average toward itself. The expectation is also called the first moment and is written μ=E[X]\mu=\mathbb{E}[X]. A fair die has E[X]=16(1+2+3+4+5+6)=216=3.5\mathbb{E}[X]=\tfrac16(1+2+3+4+5+6)=\tfrac{21}{6}=3.5 (Example 13.1) — a decisive reminder that the mean need not be a value XX can take: no face shows 3.53.5. A useful special case is the indicator 1A\mathbf{1}_A, equal to 11 when the event AA occurs and 00 otherwise; since P{1A=1}=P(A)\mathbb{P}\{\mathbf{1}_A=1\}=\mathbb{P}(A), we get E[1A]=P(A)\mathbb{E}[\mathbf{1}_A]=\mathbb{P}(A), so every probability is itself an expectation. Whether the defining sum actually produces a number becomes a genuine question once XX has infinitely many values — the subject of Remark 13.1 below.

2

Expectation of a continuous random variable

When XX is continuous with density ff, averaging is still 'value times weight', but the weights come from the density and the sum turns into an integral: E[X]=∫−∞∞x f(x) dx\mathbb{E}[X]=\int_{-\infty}^{\infty} x\,f(x)\,dx (Definition 13.2), again written μ=E[X]\mu=\mathbb{E}[X]. A thin slice near xx carries probability f(x) dxf(x)\,dx, and x f(x) dxx\,f(x)\,dx is its contribution to the average — exactly mirroring the term k P{X=k}k\,\mathbb{P}\{X=k\} in the discrete sum. The cleanest case is the uniform variable X∼Unif[a,b]X\sim\mathrm{Unif}[a,b], whose density is the constant 1b−a\tfrac{1}{b-a} on [a,b][a,b]: E[X]=∫abx⋅1b−a dx=1b−a⋅b2−a22=a+b2\mathbb{E}[X]=\int_a^b x\cdot\frac{1}{b-a}\,dx=\frac{1}{b-a}\cdot\frac{b^2-a^2}{2}=\frac{a+b}{2} (Example 13.7) — the midpoint of the interval, just as symmetry suggests. The same integral can diverge: the density f(x)=x−2f(x)=x^{-2} on [1,∞)[1,\infty) is perfectly legitimate, yet ∫1∞x⋅x−2 dx=∫1∞1x dx=∞\int_1^{\infty} x\cdot x^{-2}\,dx=\int_1^{\infty}\tfrac1x\,dx=\infty, so that variable has infinite mean (Example 13.8).

3

LOTUS and the moments of $X$

Often we want the average not of XX but of a function g(X)g(X) — a squared value, a payoff, a cost. One route is to work out the distribution of the new variable Y=g(X)Y=g(X) and sum ∑jj P{Y=j}\sum_j j\,\mathbb{P}\{Y=j\}; the law of the unconscious statistician (LOTUS, Proposition 13.1) says we may skip that step and weight gg directly against the distribution of XX: E[g(X)]=∑kg(k) P{X=k}\mathbb{E}[g(X)]=\sum_k g(k)\,\mathbb{P}\{X=k\} for discrete XX (and ∫−∞∞g(x) f(x) dx\int_{-\infty}^{\infty} g(x)\,f(x)\,dx in the continuous case). The name is a joke — you use the p.m.f. of XX 'unconsciously', without re-deriving anything. Taking g(x)=xng(x)=x^n produces the moments of XX: the nn-th moment is E[Xn]=∑kkn P{X=k}\mathbb{E}[X^n]=\sum_k k^n\,\mathbb{P}\{X=k\} (Definition 13.3). The first moment (n=1n=1) is just the mean μ\mu; the second moment E[X2]\mathbb{E}[X^2] is the key ingredient of the variance, taken up in a later lesson. Beware that E[g(X)]≠g(E[X])\mathbb{E}[g(X)]\neq g(\mathbb{E}[X]) in general — for a fair die, LOTUS gives E[X2]=16(1+4+9+16+25+36)=916≈15.17\mathbb{E}[X^2]=\tfrac16(1+4+9+16+25+36)=\tfrac{91}{6}\approx15.17, well above (E[X])2=12.25(\mathbb{E}[X])^2=12.25.

4

When an expectation is infinite or undefined

An expectation is a sum or integral, and those do not always converge, so E[X]\mathbb{E}[X] need not exist as a finite number. Remark 13.1 fixes the vocabulary: E[X]\mathbb{E}[X] is well-defined if its defining sum or integral has a definite value — a finite number, or +∞+\infty, or −∞-\infty. Two failure modes are worth seeing. First, the value can be infinite: in a doubling-prize coin game you win 2n2^n with probability 2−n2^{-n}, so E[X]=∑n≥12n⋅2−n=∑n≥11=∞,\mathbb{E}[X]=\sum_{n\ge1} 2^n\cdot 2^{-n}=\sum_{n\ge1}1=\infty, even though the prize is finite every single time you play (Example 13.5; the continuous Example 13.8 behaves similarly). Second, the value can be undefined: if the positive and negative parts each sum to infinity there is no consistent total — a net-reward game leads to 1−1+1−1+⋯1-1+1-1+\cdots, a series with no limit, so E[X]\mathbb{E}[X] simply does not exist (Example 13.6). Finally, keep in mind that a mean is not a probability: it can be negative, and it need not lie in [0,1][0,1].

Definition 13.1 — Expectation (discrete)

The expectation (or mean) of a discrete random variable XX is E[X]=∑kk P{X=k},\mathbb{E}[X]=\sum_k k\,\mathbb{P}\{X=k\}, the sum taken over all possible values kk of XX. It is also called the first moment and is denoted μ=E[X]\mu=\mathbb{E}[X].

Intuition. Read it as a weighted average: list the values XX can take, weight each by its probability, and add. Values carrying more probability mass pull the average toward them. The mean is a summary of location — and, as the fair die (E[X]=3.5\mathbb{E}[X]=3.5) shows, it need not be a value XX ever actually takes.
Definition 13.2 — Expectation (continuous)

The expectation (or mean) of a continuous random variable XX with density ff is E[X]=∫−∞∞x f(x) dx,\mathbb{E}[X]=\int_{-\infty}^{\infty} x\,f(x)\,dx, also written μ=E[X]\mu=\mathbb{E}[X].

Intuition. This is the discrete average with the sum replaced by an integral and the mass P{X=k}\mathbb{P}\{X=k\} replaced by f(x) dxf(x)\,dx. Each location xx contributes xx times the probability f(x) dxf(x)\,dx of landing near it; adding these contributions across the whole line gives the balance point of the density.
Proposition 13.1 — Law of the unconscious statistician (LOTUS)

Let gg be a real-valued function defined on the range of a random variable XX. If XX is discrete, then E[g(X)]=∑kg(k) P{X=k}.\mathbb{E}[g(X)]=\sum_k g(k)\,\mathbb{P}\{X=k\}. (For continuous XX with density ff, E[g(X)]=∫−∞∞g(x) f(x) dx\mathbb{E}[g(X)]=\int_{-\infty}^{\infty} g(x)\,f(x)\,dx.)

Intuition. To average a function of XX you do not need the distribution of g(X)g(X): apply gg to each value and weight by the original probabilities. It is called 'unconscious' because you reuse the p.m.f. of XX without pausing to re-derive the distribution of the new variable g(X)g(X).
Definition 13.3 — Moments

For a positive integer nn, the nn-th moment of a random variable XX is E[Xn]\mathbb{E}[X^n]. By LOTUS, for discrete XX this is E[Xn]=∑kkn P{X=k}\mathbb{E}[X^n]=\sum_k k^n\,\mathbb{P}\{X=k\}. The first moment (n=1n=1) is the mean μ=E[X]\mu=\mathbb{E}[X].

Intuition. Moments are the expectations of the successive powers of XX, and they package increasingly detailed information about its distribution. The first moment locates the centre; the second moment E[X2]\mathbb{E}[X^2] feeds into the spread (variance), developed later.

Worked examples

Example 1

Example 13.1 — a fair die. Let XX be the result of rolling a fair die, so XX takes each value in {1,2,3,4,5,6}\{1,2,3,4,5,6\} with P{X=k}=16\mathbb{P}\{X=k\}=\tfrac16. Compute the expectation E[X]\mathbb{E}[X], and say whether the mean is a possible value of XX.

  1. 1

    Set up Definition 13.1. E[X]=∑k=16k P{X=k}=∑k=16k⋅16.\mathbb{E}[X]=\sum_{k=1}^{6} k\,\mathbb{P}\{X=k\}=\sum_{k=1}^{6} k\cdot\tfrac16. Every value shares the same weight 16\tfrac16, so the mean is the ordinary average of 1,…,61,\dots,6.

  2. 2

    Add the values. 1+2+3+4+5+6=211+2+3+4+5+6=21, hence E[X]=16⋅21=216=72.\mathbb{E}[X]=\tfrac16\cdot 21=\tfrac{21}{6}=\tfrac72.

  3. 3

    Interpret. 72=3.5\tfrac72=3.5 is the balance point of the six equally likely faces, but no face shows 3.53.5 — the mean is a summary, not an outcome.

Answer. E[X]=216=72=3.5\mathbb{E}[X]=\tfrac{21}{6}=\tfrac72=3.5, which is not one of the possible values of XX.
Example 2

A payoff game (mean and a moment via LOTUS). You play a game whose net payoff XX (in dollars) has p.m.f. P{X=−1}=0.3\mathbb{P}\{X=-1\}=0.3, P{X=2}=0.5\mathbb{P}\{X=2\}=0.5, P{X=5}=0.2\mathbb{P}\{X=5\}=0.2. Find the expected payoff E[X]\mathbb{E}[X], and then the second moment E[X2]\mathbb{E}[X^2].

Example 3

Example 13.7 — mean of a uniform variable. Let X∼Unif[a,b]X\sim\mathrm{Unif}[a,b], with density f(x)=1b−af(x)=\tfrac{1}{b-a} on [a,b][a,b] and 00 elsewhere. Derive E[X]\mathbb{E}[X] in general, then evaluate it for X∼Unif[2,8]X\sim\mathrm{Unif}[2,8].