Continuous random variables
A-Level Mathematics · Probability & Statistics — Further
The probability density function
A function $f$ is a valid pdf when $f(x)\ge 0$ everywhere and
$$\int_{-\infty}^{\infty}f(x)\,dx=1$$Probability is area: $P(a\lt X\lt b)=\displaystyle\int_{a}^{b}f(x)\,dx$. Consequently $P(X=c)=0$ for every single value $c$, so strict and non-strict inequalities give the same probability — unlike the discrete case.
Expectation, variance, median
$$\text{E}(X)=\int xf(x)\,dx,\qquad \text{E}\left(X^{2}\right)=\int x^{2}f(x)\,dx,\qquad \text{Var}(X)=\text{E}\left(X^{2}\right)-\big[\text{E}(X)\big]^{2}$$The median $m$ splits the area in half:
$$\int_{-\infty}^{m}f(x)\,dx=\tfrac{1}{2}$$The cumulative distribution function
$$F(x)=P(X\le x)=\int_{-\infty}^{x}f(t)\,dt,\qquad f(x)=F'(x)$$$F$ must be written piecewise: $0$ below the range, the integral inside it, and $1$ above.
Worked example: find the normalizing constant and the expectation
A continuous random variable $X$ has probability density function $f(x)=kx(4-x)$ for $0\le x\le 4$, and $0$ elsewhere. Find $k$, then find $\text{E}(X)$ and $\text{Var}(X)$.
Solution
Step 1 — normalizing constant. The total area must equal $1$:
$$\int_{0}^{4}k\left(4x-x^{2}\right)dx=k\left[2x^{2}-\frac{x^{3}}{3}\right]_{0}^{4}=k\left(32-\frac{64}{3}\right)=k\cdot\frac{32}{3}=1$$$$k=\frac{3}{32}$$Step 2 — expectation. The graph is symmetric about $x=2$, so we can read off $\text{E}(X)=2$ immediately; the calculation below confirms it:
$$\text{E}(X)=\int_{0}^{4}x\cdot\frac{3}{32}\left(4x-x^{2}\right)dx=\frac{3}{32}\left[\frac{4x^{3}}{3}-\frac{x^{4}}{4}\right]_{0}^{4}=\frac{3}{32}\left(\frac{256}{3}-64\right)=\frac{3}{32}\cdot\frac{64}{3}=2$$Step 3 — variance.
$$\text{E}\left(X^{2}\right)=\frac{3}{32}\int_{0}^{4}\left(4x^{3}-x^{4}\right)dx=\frac{3}{32}\left[x^{4}-\frac{x^{5}}{5}\right]_{0}^{4}=\frac{3}{32}\left(256-\frac{1024}{5}\right)=\frac{3}{32}\cdot\frac{256}{5}=\frac{24}{5}$$$$\text{Var}(X)=\frac{24}{5}-2^{2}=\frac{24-20}{5}=\frac{4}{5}=0.8$$Sense check: $X$ ranges over an interval $4$ units long but is concentrated toward the middle, so the standard deviation $\sqrt{0.8}=0.89$ is much smaller than half the width of the interval. Reasonable.
Worked example: from density to cumulative distribution function
Given $f(x)=\dfrac{x}{2}$ for $0\le x\le 2$ and $0$ elsewhere. Find the cumulative distribution function $F$, and use it to find the median.
Solution
Step 1 — integrate within the range.
$$F(x)=\int_{0}^{x}\frac{t}{2}\,dt=\left[\frac{t^{2}}{4}\right]_{0}^{x}=\frac{x^{2}}{4}\qquad(0\le x\le 2)$$Step 2 — write all three pieces. This is the most commonly forgotten step, and it has its own mark:
$$F(x)=\begin{cases}0 & x<0\\[4pt] \dfrac{x^{2}}{4} & 0\le x\le 2\\[4pt] 1 & x>2\end{cases}$$Check both endpoints: $F(0)=0$ and $F(2)=\dfrac{4}{4}=1$. If $F(2)$ does not come out as $1$, the normalizing constant was certainly wrong earlier.
Step 3 — median. The median is the value that makes $F$ equal to $\dfrac{1}{2}$:
$$\frac{m^{2}}{4}=\frac{1}{2}\;\Longrightarrow\;m^{2}=2\;\Longrightarrow\;m=\sqrt{2}\approx 1.41$$Notice that the median $1.41$ is greater than the midpoint of the interval ($1$), exactly as it should be: the density increases, so the probability mass is pushed to the right. The expectation here is $\dfrac{4}{3}\approx 1.33$, which also differs from the median — this density is not symmetric, so the shortcut must not be used.