Technopedia

The technologist’s encyclopedia

Random variables and expectation

A random variable is a measurable function from a sample space to a numerical space. Expectation, variance, and higher moments summarize its distribution into single numbers. Concentration inequalities bound the probability of large deviations. These tools are the computational core of probability: they turn a measure into quantities that can be compared, optimized, and bounded.

Authoritative sources

Measurable functions as random variables

A random variable is a measurable map X:(Ω,F)→(R,B(R))X: (\Omega, \mathcal{F}) \to (\mathbb{R}, \mathcal{B}(\mathbb{R})) such that X−1(B)∈FX^{-1}(B) \in \mathcal{F} for every Borel set BB.

The pushforward measure X∗PX_*P on (R,B(R))(\mathbb{R}, \mathcal{B}(\mathbb{R})) is the distribution of XX (see Distributions).

Sample space (Ω, F, P) ω₁ ω₂ ω₃ ω₄ outcomes ω, no numbers yet X measurable: X⁻¹(B) ∈ F for every Borel B Borel set B Value space ℝ pushforward X*P = law of X P(X ∈ B) = P(X⁻¹(B))
Details

The measurability requirement ensures that events of the form {ω:X(ω)∈B}\{\omega : X(\omega) \in B\} are in the sigma-algebra, so they have a well-defined probability. For a finite or countable sample space every function is measurable; the condition only becomes restrictive for uncountable spaces. The general notion of a measurable map between measure spaces is developed in Measurable functions.

The sigma-algebra generated by XX is σ(X)={X−1(B):B∈B(R)}\sigma(X) = \{X^{-1}(B) : B \in \mathcal{B}(\mathbb{R})\}. Two random variables X,YX, Y are independent iff σ(X)\sigma(X) and σ(Y)\sigma(Y) are independent sigma-algebras (see Conditional probability).

Worked example (pushforward of a finite space). Flip two fair coins: Ω={HH,HT,TH,TT}\Omega = \{HH, HT, TH, TT\} with P(ω)=1/4P(\omega) = 1/4 each, and let X(ω)X(\omega) = number of heads. The pushforward assigns P(X=0)=1/4P(X=0) = 1/4 (only TTTT), P(X=1)=1/2P(X=1) = 1/2 (HT,THHT, TH), P(X=2)=1/4P(X=2) = 1/4 (only HHHH). All the probability questions about XX — its mean, its tails — now live on the real line, where they can be computed with the tools below. This is exactly the distribution the Distributions page calls Binomial(2, 1/2).

Example problem. Let XX be the constant random variable X(ω)=cX(\omega) = c on any sample space. What is σ(X)\sigma(X), and what is the pushforward measure X∗PX_*P?

Solution

X−1(B)X^{-1}(B) is Ω\Omega if c∈Bc \in B and ∅\emptyset otherwise, so σ(X)={∅,Ω}\sigma(X) = \{\emptyset, \Omega\} — the trivial sigma-algebra: a constant random variable carries no information. The pushforward is the Dirac measure δc\delta_c on R\mathbb{R}: all mass at the point cc. Its expectation is cc and its variance is 00, as the formulas below confirm.

Expectation

The expectation (mean) of an integrable random variable XX is

E[X]=∫ΩX dP\mathbb{E}[X] = \int_\Omega X\, dP

For a discrete XX: E[X]=∑xx P(X=x)\mathbb{E}[X] = \sum_x x\, P(X=x). For a continuous XX with density ff: E[X]=∫x f(x) dx\mathbb{E}[X] = \int x\, f(x)\, dx.

Linearity: E[aX+bY]=a E[X]+b E[Y]\mathbb{E}[aX + bY] = a\,\mathbb{E}[X] + b\,\mathbb{E}[Y] for any constants a,ba, b (no independence needed).

Details

The expectation is the Lebesgue integral of XX with respect to the probability measure PP. It exists (is finite) iff ∫∣X∣ dP<∞\int |X|\, dP < \infty. The integral is defined on the measure space (Ω,F,P)(\Omega, \mathcal{F}, P); see Measure theory and the Lebesgue integral for the general framework.

The transformation rule (law of the unconscious statistician). Expectations are almost never computed on Ω\Omega; one pushes forward to the real line first. For any measurable gg:

E[g(X)]=∫Ωg(X) dP=∫Rg(x) dFX(x)=∑xg(x) P(X=x)  or  ∫Rg(x)f(x) dx\mathbb{E}[g(X)] = \int_\Omega g(X)\, dP = \int_{\mathbb{R}} g(x)\, dF_X(x) = \sum_x g(x)\, P(X=x) \ \text{ or } \ \int_{\mathbb{R}} g(x) f(x)\, dx

depending on whether the law of XX is atomic or has density ff. This is the bridge to the Distributions page: every practical expectation is an integral against the distribution, not against PP. When gg is differentiable and one only needs E[g(X)]\mathbb{E}[g(X)] approximately, the delta method replaces gg by its first-order Taylor expansion around E[X]\mathbb{E}[X]: E[g(X)]≈g(E[X])+12g′′(E[X])Var⁡(X)\mathbb{E}[g(X)] \approx g(\mathbb{E}[X]) + \tfrac{1}{2} g''(\mathbb{E}[X]) \operatorname{Var}(X).

Key properties:

Jensen's inequality for a convex φ φ E[X] φ(E[X]) E[φ(X)] on the chord

Worked example. For a fair die, E[X]=(1+2+3+4+5+6)/6=3.5\mathbb{E}[X] = (1+2+3+4+5+6)/6 = 3.5. Using the transformation rule with g(x)=x2g(x) = x^2: E[X2]=(1+4+9+16+25+36)/6=91/6≈15.17\mathbb{E}[X^2] = (1+4+9+16+25+36)/6 = 91/6 \approx 15.17. Jensen is visible here: E[X2]=15.17≥(E[X])2=12.25\mathbb{E}[X^2] = 15.17 \geq (\mathbb{E}[X])^2 = 12.25, with the gap being exactly the variance. The transformation rule also carries a warning: for X∼Unif[0,1]X \sim \text{Unif}[0,1] and g(x)=1/xg(x) = 1/x, the integral ∫01dxx\int_0^1 \frac{dx}{x} diverges, so E[1/X]=∞\mathbb{E}[1/X] = \infty even though gg is smooth — finiteness must always be checked.

Authoritative sources

Example problem. Let X∼Unif[0,1]X \sim \text{Unif}[0,1]. Compute E[X2]\mathbb{E}[X^2] and E[eX]\mathbb{E}[e^X] using the transformation rule.

Solution

The density is f(x)=1f(x) = 1 on [0,1][0,1], so E[g(X)]=∫01g(x) dx\mathbb{E}[g(X)] = \int_0^1 g(x)\, dx:

  • E[X2]=∫01x2 dx=13\mathbb{E}[X^2] = \int_0^1 x^2\, dx = \frac{1}{3}.
  • E[eX]=∫01ex dx=e−1≈1.718\mathbb{E}[e^X] = \int_0^1 e^x\, dx = e - 1 \approx 1.718.

Note that neither computation ever mentioned the sample space Ω\Omega — the pushforward to [0,1][0,1] did all the work.

Variance and covariance

Var⁡(X)=E[(X−E[X])2]=E[X2]−(E[X])2\operatorname{Var}(X) = \mathbb{E}[(X - \mathbb{E}[X])^2] = \mathbb{E}[X^2] - (\mathbb{E}[X])^2 Cov⁡(X,Y)=E[(X−μX)(Y−μY)]=E[XY]−μXμY\operatorname{Cov}(X, Y) = \mathbb{E}[(X - \mu_X)(Y - \mu_Y)] = \mathbb{E}[XY] - \mu_X \mu_Y

The correlation coefficient is ρ=Cov⁡(X,Y)/(σXσY)∈[−1,1]\rho = \operatorname{Cov}(X,Y) / (\sigma_X \sigma_Y) \in [-1, 1].

Standard normal density: mean μ and variance bands μ μ−σ μ+σ μ−2σ μ+2σ ≈ 68% of mass ≈ 13.5% ≈ 13.5% variance σ² sets the width: larger σ² ⇒ flatter, wider density
Details

Variance measures spread around the mean. For independent X,YX, Y: Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)\operatorname{Var}(X+Y) = \operatorname{Var}(X) + \operatorname{Var}(Y) (the cross term vanishes). Without independence, Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)+2Cov⁡(X,Y)\operatorname{Var}(X+Y) = \operatorname{Var}(X) + \operatorname{Var}(Y) + 2\operatorname{Cov}(X,Y). Variance is homogeneous of degree 2: Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X).

Zero covariance does not imply independence. Discrete example: let XX be uniform on {−1,0,1}\{-1, 0, 1\} and Y=X2Y = X^2. Then Cov⁡(X,Y)=E[X3]−E[X] E[X2]=0−0⋅23=0\operatorname{Cov}(X, Y) = \mathbb{E}[X^3] - \mathbb{E}[X]\,\mathbb{E}[X^2] = 0 - 0 \cdot \frac{2}{3} = 0, yet YY is a deterministic function of XX, so the two are maximally dependent. Independence implies zero covariance, but not conversely — covariance only detects linear dependence.

Worked example. For the fair die: E[X2]=91/6\mathbb{E}[X^2] = 91/6 and (E[X])2=12.25=49/4(\mathbb{E}[X])^2 = 12.25 = 49/4, so

Var⁡(X)=916−494=182−14712=3512≈2.917,σ≈1.708\operatorname{Var}(X) = \frac{91}{6} - \frac{49}{4} = \frac{182 - 147}{12} = \frac{35}{12} \approx 2.917, \qquad \sigma \approx 1.708

Example problem. Using the die’s variance 35/1235/12, compute Var⁡(2X+3)\operatorname{Var}(2X + 3) without recomputing any expectation.

Solution

Shifts do not change spread and scaling squares: Var⁡(2X+3)=22Var⁡(X)=4⋅3512=353≈11.67\operatorname{Var}(2X + 3) = 2^2 \operatorname{Var}(X) = 4 \cdot \frac{35}{12} = \frac{35}{3} \approx 11.67. The constant 3 contributes nothing because Var⁡(b)=0\operatorname{Var}(b) = 0 — a constant has no spread around its own mean.

Moment generating function

The moment generating function (MGF) of XX is

MX(t)=E[etX]=∫etx dFX(x)M_X(t) = \mathbb{E}[e^{tX}] = \int e^{tx}\, dF_X(x)

where FXF_X is the CDF. If MXM_X is finite in a neighborhood of 0, then MX(n)(0)=E[Xn]M_X^{(n)}(0) = \mathbb{E}[X^n], and MXM_X uniquely determines the distribution of XX (by analytic continuation: MXM_X is holomorphic on that neighborhood, and by the identity theorem two MGFs agreeing there agree everywhere, hence the distributions coincide).

Details

Why the MGF and not the moment sequence? Moments do not always determine a distribution: this is the Stieltjes/Hamburger moment problem. Classic example: the log-normal distributions with density f(x)∝x−1exp⁡(−(ln⁡x−μ)2/2)f(x) \propto x^{-1} \exp(-(\ln x - \mu)^2/2) (for suitable parameter pairs) share all their moments yet are different laws. So knowing every moment is not enough in general. What saves the day is analyticity: when MXM_X is finite on an open interval around 0, it is a holomorphic function there, the identity theorem for holomorphic functions propagates its values from that interval to the whole complex plane, and the distribution is pinned down. When even that fails (heavy tails), one falls back on the characteristic function, for which the inversion theorem always holds.

Cumulants. The cumulant generating function is KX(t)=log⁡MX(t)K_X(t) = \log M_X(t); its derivatives at 0 give the cumulants. The first two cumulants are the mean and variance. The third and fourth cumulants, suitably standardized, are the skewness κ3/σ3\kappa_3/\sigma^3 (asymmetry of the distribution) and the excess kurtosis κ4/σ4\kappa_4/\sigma^4 (tail heaviness relative to a normal) — the standard descriptors beyond mean and variance.

Sums. For independent X1,…,XnX_1, \ldots, X_n: M∑Xi(t)=∏iMXi(t)M_{\sum X_i}(t) = \prod_i M_{X_i}(t). This multiplicative property is the workhorse behind the Central Limit Theorem (see Limit theorems).

Worked example. Let X∼Exp(λ)X \sim \text{Exp}(\lambda) (density λe−λx\lambda e^{-\lambda x} on x≥0x \geq 0). Then

MX(t)=∫0∞etxλe−λx dx=λλ−t(t<λ)M_X(t) = \int_0^\infty e^{tx} \lambda e^{-\lambda x}\, dx = \frac{\lambda}{\lambda - t} \quad (t < \lambda)

Differentiating: MX′(0)=1/λM_X'(0) = 1/\lambda (the mean) and MX′′(0)=2/λ2M_X''(0) = 2/\lambda^2, so Var⁡(X)=2/λ2−1/λ2=1/λ2\operatorname{Var}(X) = 2/\lambda^2 - 1/\lambda^2 = 1/\lambda^2. Note the MGF only exists for t<λt < \lambda — a neighborhood of 0, which is all the uniqueness argument needs.

For variables where the MGF does not exist at all (e.g. Cauchy), the characteristic function φX(t)=E[eitX]\varphi_X(t) = \mathbb{E}[e^{itX}] always exists (it is bounded by 1) and serves the same role; the inversion theorem applies to it.

Authoritative sources Authoritative sources

Solution

By independence, MS(t)=M(t)2=(1−p+pet)2=(1−p)2+2p(1−p)et+p2e2tM_S(t) = M(t)^2 = (1 - p + p e^t)^2 = (1-p)^2 + 2p(1-p)e^t + p^2 e^{2t}. Reading off the coefficients of ekte^{kt}: P(S=0)=(1−p)2P(S=0) = (1-p)^2, P(S=1)=2p(1−p)P(S=1) = 2p(1-p), P(S=2)=p2P(S=2) = p^2 — the Binomial(2, pp) law. This is the MGF proof that sums of independent Bernoullis are binomial, and it scales verbatim to nn terms.

Concentration inequalities

Markov’s inequality. For X≥0X \geq 0 and a>0a > 0:

P(X≥a)≤E[X]aP(X \geq a) \leq \frac{\mathbb{E}[X]}{a}

Chebyshev’s inequality. For any random variable with finite variance:

P(∣X−μ∣≥kσ)≤1k2P(|X - \mu| \geq k\sigma) \leq \frac{1}{k^2}

Hoeffding’s inequality. For independent bounded Xi∈[ai,bi]X_i \in [a_i, b_i]:

P ⁣(Xˉ−E[Xˉ]≥t)≤exp⁡ ⁣(−2n2t2∑i(bi−ai)2)P\!\left(\bar{X} - \mathbb{E}[\bar{X}] \geq t\right) \leq \exp\!\left(-\frac{2n^2 t^2}{\sum_i (b_i - a_i)^2}\right) Tail bounds: how fast each bound decays with the deviation deviation t (in units of σ or of the bound's scale) bound on P(X ≥ t), log scale 1 10⁻² 10⁻⁴ Markov: 1/t Chebyshev: 1/t² Hoeffding: e^(−2t²) each bound uses stronger hypotheses (mean → variance → boundedness + independence)
Details

These inequalities bound tail probabilities using only moments or boundedness, without knowing the full distribution. Each stronger hypothesis buys a faster decay, as the plot above shows.

Worked example. Roll a fair die n=100n = 100 times; μ=3.5\mu = 3.5, σ2=35/12\sigma^2 = 35/12, support width b−a=5b - a = 5. Bound P(∣Xˉ−3.5∣≥1)P(|\bar{X} - 3.5| \geq 1):

Hoeffding is about 40× sharper here. The comparison flips near the mean (small ε\varepsilon), where Chebyshev’s 1/ε21/\varepsilon^2 can beat Hoeffding’s e−cε2e^{-c\varepsilon^2} — each bound wins in its own regime, and the plot above shows why: polynomial vs exponential decay.

For sub-Gaussian variables (e.g. normal), Hoeffding-type bounds hold with a variance proxy. For sub-exponential variables, the tail is exp⁡(−ct)\exp(-ct) rather than exp⁡(−ct2)\exp(-ct^2).

These inequalities are the probabilistic backbone of the law of large numbers (see Limit theorems) and of statistical estimation (see Statistical inference).

Authoritative sources

Example problem. A sensor reads a value in [0,10][0, 10] with unknown mean μ\mu. You average n=400n = 400 independent readings. Give a bound (valid with no distributional assumptions beyond boundedness) on P(∣Xˉ−μ∣≥0.5)P(|\bar{X} - \mu| \geq 0.5).

Solution

Hoeffding with a=0a = 0, b=10b = 10, n=400n = 400, t=0.5t = 0.5:

P(∣Xˉ−μ∣≥0.5)≤2exp⁡ ⁣(−2⋅400⋅0.25100)=2e−2≈0.27P(|\bar{X} - \mu| \geq 0.5) \leq 2\exp\!\left(-\frac{2 \cdot 400 \cdot 0.25}{100}\right) = 2e^{-2} \approx 0.27

No variance estimate is needed — boundedness alone suffices. (Chebyshev cannot even be applied here without estimating σ2\sigma^2, which is exactly the situation Hoeffding was designed for.)

The simulation below runs the law of large numbers live: each trial draws up to 400 i.i.d. samples and tracks the running sample mean, while the empirical tail probability P(∣Xˉ−μ∣≥ε)P(|\bar{X} - \mu| \geq \varepsilon) (estimated over many trials) is compared against the Chebyshev and Hoeffding bounds. Increase the number of trials and watch the empirical curve settle below both bounds, exactly as the inequalities guarantee.

Quiz

Quiz: the sample mean of i.i.d. variables

Let X1,…,XnX_1, \ldots, X_n be i.i.d. with E[Xi]=μ\mathbb{E}[X_i] = \mu and Var⁡(Xi)=σ2\operatorname{Var}(X_i) = \sigma^2, and let Xˉ=1n∑iXi\bar{X} = \frac{1}{n}\sum_i X_i.

  1. Compute E[Xˉ]\mathbb{E}[\bar{X}] and Var⁡(Xˉ)\operatorname{Var}(\bar{X}).
  2. Use Chebyshev to bound P(∣Xˉ−μ∣≥ε)P(|\bar{X} - \mu| \geq \varepsilon).
  3. What does the bound say as n→∞n \to \infty, and which theorem sharpens it?
How to solve it

Step 1 — expectation, by linearity. Linearity needs no independence:

E[Xˉ]=1n∑i=1nE[Xi]=1n⋅nμ=μ\mathbb{E}[\bar{X}] = \frac{1}{n}\sum_{i=1}^n \mathbb{E}[X_i] = \frac{1}{n} \cdot n\mu = \mu

The sample mean is unbiased.

Step 2 — variance, using independence. For independent variables the cross-covariance terms vanish:

Var⁡(Xˉ)=1n2∑i=1nVar⁡(Xi)=nσ2n2=σ2n\operatorname{Var}(\bar{X}) = \frac{1}{n^2}\sum_{i=1}^n \operatorname{Var}(X_i) = \frac{n\sigma^2}{n^2} = \frac{\sigma^2}{n}

Step 3 — Chebyshev. Apply Chebyshev to Xˉ\bar{X}, whose mean is μ\mu and standard deviation is σ/n\sigma/\sqrt{n}:

P(∣Xˉ−μ∣≥ε)≤Var⁡(Xˉ)ε2=σ2n ε2P(|\bar{X} - \mu| \geq \varepsilon) \leq \frac{\operatorname{Var}(\bar{X})}{\varepsilon^2} = \frac{\sigma^2}{n\,\varepsilon^2}

Step 4 — read off the limit. For fixed ε>0\varepsilon > 0 the bound tends to 0 as n→∞n \to \infty: the sample mean converges in probability to μ\mu — this is precisely the (weak) law of large numbers, proved here with nothing but linearity, independence, and Chebyshev. The Central Limit Theorem (see Limit theorems) sharpens the statement: n(Xˉ−μ)⇒N(0,σ2)\sqrt{n}(\bar{X} - \mu) \Rightarrow \mathcal{N}(0, \sigma^2), replacing the polynomial bound with an accurate normal tail.