Probability & Statistics · Unit 1 · Topic 03

Random variables: outcomes turned into numbers.

Short answer

A random variable \(X\) gives a number to each outcome. Its mean is \(E(X) = \sum x\,p(x)\) (discrete) or \(\int x f(x)\,dx\) (continuous), and

\[\operatorname{Var}(X) = E(X^2) - \big[E(X)\big]^2\]

For the score on a fair die, \(E(X) = 3.5\) and \(\operatorname{Var}(X) = \dfrac{35}{12}\).

Engineering MathsBScStatistics
01

What a random variable is

Before you start: you need basic probability. For continuous variables you also need definite integrals, and improper integrals when the range is infinite.

A random variable \(X\) attaches a number to each outcome of an experiment. Toss two coins and let \(X\) be the number of heads: \(HH \mapsto 2\), \(HT \mapsto 1\), \(TH \mapsto 1\), \(TT \mapsto 0\). Once outcomes are numbers, you can average them, and that is where expectation and variance come from.

\(X\) is discrete if it takes separate values you can list (number of heads, number of defectives). It is continuous if it can take any value in an interval (a lifetime, a length, a waiting time).

Discrete: probability mass function (pmf)

\(p(x) = P(X = x)\), with \(p(x) \ge 0\) and \(\displaystyle\sum_x p(x) = 1\).

Continuous: probability density function (pdf)

\(f(x) \ge 0\), \(\displaystyle\int_{-\infty}^{\infty} f(x)\,dx = 1\), and \[P(a \le X \le b) = \int_a^b f(x)\,dx\]

Cumulative distribution function (cdf)

\(F(x) = P(X \le x)\). It rises from 0 to 1. For a continuous \(X\), \(F'(x) = f(x)\) wherever \(f\) is continuous.

A pdf value is not a probability. For a continuous \(X\), probability is area under the curve, and the area above a single point is zero, so \(P(X = a) = 0\). This is also why \(\le\) and \(<\) give the same answer for continuous variables.

02

Expectation and variance

Mean (expectation)

\[E(X) = \sum_x x\,p(x) \qquad\text{or}\qquad E(X) = \int_{-\infty}^{\infty} x\,f(x)\,dx\]

Variance and standard deviation

\[\operatorname{Var}(X) = E(X^2) - \big[E(X)\big]^2, \qquad \sigma = \sqrt{\operatorname{Var}(X)}\]

Linear change

\(E(aX + b) = a\,E(X) + b\) and \(\operatorname{Var}(aX + b) = a^2\operatorname{Var}(X)\)

\(E(X)\) is the long-run average: roll a die thousands of times and the average score settles near 3.5. Variance measures spread around that average. Adding a constant \(b\) moves every value by the same amount, so the spread does not change. Multiplying by \(a\) stretches every distance from the mean by \(a\), so the squared distances grow by \(a^2\).

  1. Check it is a valid pmf or pdf, or use the condition "total = 1" to find an unknown constant \(k\).
  2. Find \(E(X)\) by summing \(x\,p(x)\) or integrating \(x f(x)\).
  3. Find \(E(X^2)\) the same way with \(x^2\).
  4. Subtract: \(\operatorname{Var}(X) = E(X^2) - [E(X)]^2\).
03

Solved examples

Example 1: Score on a die

Easy

\(X\) is the score on a fair die. Find \(E(X)\) and \(\operatorname{Var}(X)\).

  1. Each value has \(p(x) = \tfrac{1}{6}\). \(E(X) = \dfrac{1 + 2 + \cdots + 6}{6} = \dfrac{21}{6} = \dfrac{7}{2}\).
  2. \(E(X^2) = \dfrac{1 + 4 + 9 + 16 + 25 + 36}{6} = \dfrac{91}{6}\).
  3. \(\operatorname{Var}(X) = \dfrac{91}{6} - \dfrac{49}{4} = \dfrac{182 - 147}{12}\).

Answer\(E(X) = \dfrac{7}{2}\), \(\operatorname{Var}(X) = \dfrac{35}{12}\)

Example 2: Finding k in a pmf

Easy

\(P(X = x) = kx\) for \(x = 1, 2, 3, 4\). Find \(k\), \(P(X \ge 3)\), \(E(X)\) and \(\operatorname{Var}(X)\).

  1. Total \(= k(1 + 2 + 3 + 4) = 10k = 1\), so \(k = \dfrac{1}{10}\).
  2. \(P(X \ge 3) = \dfrac{3 + 4}{10} = \dfrac{7}{10}\).
  3. \(E(X) = \sum x\cdot\dfrac{x}{10} = \dfrac{1 + 4 + 9 + 16}{10} = 3\).
  4. \(E(X^2) = \sum \dfrac{x^3}{10} = \dfrac{1 + 8 + 27 + 64}{10} = 10\), so \(\operatorname{Var}(X) = 10 - 9 = 1\).

Answer\(k = \dfrac{1}{10}\), \(P(X \ge 3) = \dfrac{7}{10}\), \(E(X) = 3\), \(\operatorname{Var}(X) = 1\)

Example 3: A pmf table

Medium

A random variable has this distribution. Find \(k\), the mean and the variance. \[\begin{array}{c|cccccc} x & -2 & -1 & 0 & 1 & 2 & 3 \\ \hline p(x) & 0.1 & k & 0.2 & 2k & 0.3 & k \end{array}\]

  1. Total: \(0.6 + 4k = 1\), so \(k = 0.1\).
  2. \(E(X) = -0.2 - 0.1 + 0 + 0.2 + 0.6 + 0.3 = 0.8\).
  3. \(E(X^2) = 0.4 + 0.1 + 0 + 0.2 + 1.2 + 0.9 = 2.8\).
  4. \(\operatorname{Var}(X) = 2.8 - 0.8^2 = 2.8 - 0.64\).

Answer\(k = 0.1\), \(E(X) = 0.8\), \(\operatorname{Var}(X) = 2.16\)

Example 4: A linear change

Medium

For \(X\) as in Example 3, find \(E(3X + 2)\) and \(\operatorname{Var}(3X + 2)\).

  1. \(E(3X + 2) = 3(0.8) + 2 = 4.4\).
  2. \(\operatorname{Var}(3X + 2) = 3^2(2.16) = 19.44\). The \(+2\) has no effect on the spread.

Answer\(4.4\) and \(19.44\)

Example 5: Finding k in a pdf

Medium

\(f(x) = kx^2\) for \(0 \le x \le 3\), and 0 elsewhere. Find \(k\), \(P(1 \le X \le 2)\), \(E(X)\) and \(\operatorname{Var}(X)\).

  1. \(\displaystyle\int_0^3 kx^2\,dx = 9k = 1\), so \(k = \dfrac{1}{9}\).
  2. \(P(1 \le X \le 2) = \displaystyle\int_1^2 \frac{x^2}{9}\,dx = \frac{8 - 1}{27} = \frac{7}{27}\).
  3. \(E(X) = \displaystyle\int_0^3 \frac{x^3}{9}\,dx = \frac{81}{36} = \frac{9}{4}\), and \(E(X^2) = \displaystyle\int_0^3 \frac{x^4}{9}\,dx = \frac{243}{45} = \frac{27}{5}\).
  4. \(\operatorname{Var}(X) = \dfrac{27}{5} - \dfrac{81}{16} = \dfrac{432 - 405}{80}\).

Answer\(k = \dfrac{1}{9}\), \(P = \dfrac{7}{27}\), \(E(X) = \dfrac{9}{4}\), \(\operatorname{Var}(X) = \dfrac{27}{80}\)

Example 6: The cdf of a pdf

Medium

Show that \(f(x) = 6x(1 - x)\), \(0 \le x \le 1\), is a pdf. Find its cdf, \(P\left(X < \tfrac{1}{3}\right)\), the mean and the variance.

  1. \(f \ge 0\) on \([0, 1]\), and \(\displaystyle\int_0^1 (6x - 6x^2)\,dx = 3 - 2 = 1\). So it is a pdf.
  2. For \(0 \le x \le 1\): \(F(x) = \displaystyle\int_0^x (6t - 6t^2)\,dt = 3x^2 - 2x^3\). \(F = 0\) for \(x < 0\) and \(F = 1\) for \(x > 1\).
  3. \(P\left(X < \tfrac{1}{3}\right) = F\left(\tfrac{1}{3}\right) = \dfrac{3}{9} - \dfrac{2}{27} = \dfrac{7}{27}\).
  4. \(E(X) = \displaystyle\int_0^1 (6x^2 - 6x^3)\,dx = 2 - \frac{3}{2} = \frac{1}{2}\). \(E(X^2) = \displaystyle\int_0^1 (6x^3 - 6x^4)\,dx = \frac{3}{2} - \frac{6}{5} = \frac{3}{10}\).
  5. \(\operatorname{Var}(X) = \dfrac{3}{10} - \dfrac{1}{4} = \dfrac{1}{20}\).

Answer\(F(x) = 3x^2 - 2x^3\), \(P = \dfrac{7}{27}\), \(E(X) = \dfrac{1}{2}\), \(\operatorname{Var}(X) = \dfrac{1}{20}\)

Example 7: An infinite range

Exam level

\(f(x) = ke^{-2x}\) for \(x \ge 0\), and 0 for \(x < 0\). Find \(k\), \(P(X > 1)\), the mean and the variance.

  1. \(\displaystyle\int_0^\infty ke^{-2x}\,dx = \frac{k}{2} = 1\), so \(k = 2\).
  2. \(P(X > 1) = \displaystyle\int_1^\infty 2e^{-2x}\,dx = e^{-2} \approx 0.1353\).
  3. By parts, \(E(X) = \displaystyle\int_0^\infty 2x e^{-2x}\,dx = \frac{1}{2}\) and \(E(X^2) = \displaystyle\int_0^\infty 2x^2 e^{-2x}\,dx = \frac{1}{2}\).
  4. \(\operatorname{Var}(X) = \dfrac{1}{2} - \dfrac{1}{4} = \dfrac{1}{4}\). (The Gamma function gives these integrals quickly: \(\int_0^\infty x^n e^{-ax}dx = \dfrac{n!}{a^{n+1}}\).)

Answer\(k = 2\), \(P(X > 1) = e^{-2}\), \(E(X) = \dfrac{1}{2}\), \(\operatorname{Var}(X) = \dfrac{1}{4}\)

Vipul Sir's tip

After you find \(E(X)\), glance at where the values sit. In Example 5 the density piles up near \(x = 3\), so a mean of \(2.25\) looks right. A mean outside the range of \(X\), or a negative variance, means an arithmetic slip, and you can catch it before the examiner does.

04

Common mistakes

1. Getting \(\operatorname{Var}(aX + b)\) wrong

Wrong: \(\operatorname{Var}(3X + 2) = 3\operatorname{Var}(X) + 2\). Right: \(9\operatorname{Var}(X)\). The constant disappears and the multiplier is squared.

2. Writing \(E(X^2) = [E(X)]^2\)

For the die, \(E(X^2) = \dfrac{91}{6} \approx 15.17\) but \([E(X)]^2 = 12.25\). If they were equal the variance would always be zero. Work out \(E(X^2)\) separately from the pmf or pdf.

3. Reading \(f(x)\) as a probability

For a continuous \(X\), \(f(x)\) can be bigger than 1 (for \(f(x) = 2e^{-2x}\), \(f(0) = 2\)). Probabilities come from areas: integrate \(f\) over an interval.

05

Practice questions

Try each one on paper before you open the answer.

Q1\(P(X = x) = k(x + 1)\) for \(x = 0, 1, 2, 3\). Find \(k\) and \(E(X)\).

\(k(1 + 2 + 3 + 4) = 1\), so \(k = \dfrac{1}{10}\). \(E(X) = \dfrac{0 + 2 + 6 + 12}{10} = 2\).

Q2\(X\) takes values 1, 2, 3 with probabilities 0.2, 0.5, 0.3. Find the mean, variance and standard deviation.

\(E(X) = 0.2 + 1 + 0.9 = 2.1\). \(E(X^2) = 0.2 + 2 + 2.7 = 4.9\). \(\operatorname{Var}(X) = 4.9 - 4.41 = 0.49\), so \(\sigma = 0.7\).

Q3\(E(X) = 4\) and \(\operatorname{Var}(X) = 3\). Find \(E(2X + 5)\) and \(\operatorname{Var}(2X + 5)\).

\(E = 2(4) + 5 = 13\). \(\operatorname{Var} = 4(3) = 12\).

Q4\(f(x) = kx\) for \(0 \le x \le 2\). Find \(k\) and \(E(X)\).

\(\displaystyle\int_0^2 kx\,dx = 2k = 1\), so \(k = \dfrac{1}{2}\). \(E(X) = \displaystyle\int_0^2 \frac{x^2}{2}\,dx = \frac{4}{3}\).

Q5Two fair dice are rolled and \(X\) is the sum. Find \(E(X)\) without listing all 36 outcomes.

\(X = X_1 + X_2\), and expectation adds: \(E(X) = \dfrac{7}{2} + \dfrac{7}{2} = 7\).

Q6\(f(x) = 3e^{-3x}\) for \(x \ge 0\). Find \(P\left(X \le \tfrac{1}{3}\right)\) and \(E(X)\).

\(P = 1 - e^{-1} \approx 0.632\). \(E(X) = \dfrac{1}{3}\), by the same working as Example 7 with 3 in place of 2.

Stuck on a question?

Bring it to a free demo class and work through it with Vipul Sir. Book on WhatsApp.

06

Frequently asked questions

What is a random variable?

A rule that gives a number to every outcome of an experiment, such as the number of heads in three tosses or the lifetime of a bulb.

What is the difference between a pmf and a pdf?

A pmf gives actual probabilities \(P(X = x)\) for a discrete variable, and they add to 1. A pdf is a density for a continuous variable: probabilities are areas under it, and the total area is 1.

What does the expected value mean?

It is the long-run average value of \(X\) over many repeats of the experiment. It need not be a value \(X\) can actually take: a die has \(E(X) = 3.5\).

Why is Var(aX + b) equal to a² Var(X)?

Adding \(b\) shifts every value and the mean by the same amount, so distances from the mean do not change. Multiplying by \(a\) multiplies every distance by \(a\), and variance uses squared distances, so it grows by \(a^2\).

Related lessons

← All 10 Probability & Statistics topics
Vipul Sir
Written by Vipul Sir

Vipul Sir has taught mathematics for over 15 years to HSC, CBSE, ICSE, IGCSE/IB, Diploma, Engineering and BSc students at VVS Classes in Goregaon and Vile Parle, Mumbai. He teaches every class himself, concepts first and exam technique second.

Probability and Statistics

Get Probability & Statistics right, with Vipul Sir beside you.

Concept-first classes in small batches in Goregaon and Vile Parle, or online. Your first class is free.

WhatsApp↗