Instead of describing outcomes in words, it is far easier to attach a number to each outcome, such as the number of heads or the time to complete a task. A rule that does this is a random variable, and its probabilities form a distribution.
Random Variable
A random variable X is a rule that assigns a real number to every outcome of an experiment. For two coin tosses, let X be the number of heads. Then X takes the values 0, 1 and 2. A random variable is discrete if it takes a countable set of values, such as the number of defective items. It is continuous if it can take any value in an interval, such as height or time.
Definition: Random variable. A function that assigns a real number to each outcome in the sample space of a random experiment.
PMF and PDF
For a discrete variable, the probability mass function (PMF) gives p(x) = P(X = x). It satisfies p(x) ≥ 0 and the sum of all p(x) is 1. For a continuous variable, the probability density function (PDF) f(x) satisfies f(x) ≥ 0 and the total area under the curve is 1. A probability is the area under f between two points, P(a ≤ X ≤ b) = area from a to b, and the probability at a single point is zero.
Expectation and Variance
The expectation or mean of X is E(X) = sum of x × p(x) for a discrete variable. It is the long-run average value. The variance is Var(X) = E(X squared) - (E(X)) squared, where E(X squared) = sum of x squared × p(x). The standard deviation is the square root of the variance. For constants a and b, E(aX + b) = a E(X) + b and Var(aX + b) = a squared × Var(X).
Table 3.4: PMF of the number of heads in two tosses
| x | 0 | 1 | 2 | Total |
|---|---|---|---|---|
| p(x) | 0.25 | 0.50 | 0.25 | 1.00 |
| x p(x) | 0 | 0.50 | 0.50 | 1.00 |
| x squared p(x) | 0 | 0.50 | 1.00 | 1.50 |
Example 3.6: Expectation and variance of X
Problem: Find E(X) and Var(X) for the number of heads in two tosses.
Solution:
- E(X) = 0 + 0.50 + 0.50 = 1.
- E(X squared) = 0 + 0.50 + 1.00 = 1.5.
- Var(X) = 1.5 - 1 squared = 0.5.
Result: E(X) = 1 and Var(X) = 0.5, so the standard deviation is 0.707.
p = {0: 0.25, 1: 0.5, 2: 0.25}
E = sum(x * q for x, q in p.items())
V = sum(x * x * q for x, q in p.items()) - E ** 2
print(E, V, round(V ** 0.5, 3))
Output
1.0 0.5 0.707
Common mistakes
- Using a PMF idea for a continuous variable and asking for P(X = x).
- Forgetting to subtract the square of the mean when computing variance.
- Applying Var(aX + b) = a Var(X) instead of a squared Var(X).
Key takeaways
- Discrete variables use a PMF, continuous variables use a PDF.
- The probabilities of a PMF add to 1, and the area under a PDF is 1.
- E(X) = sum of x p(x).
- Var(X) = E(X squared) - (E(X)) squared.
Practice questions
- What is a random variable?
- What is the total area under a PDF?
- State the formula for variance in terms of expectations.
Answers to the practice questions
- A function that assigns a real number to each outcome of an experiment.
-
- Var(X) = E(X squared) - (E(X)) squared.
Sources
- Official BCA syllabus Probability and Statistics, course code 26BCA403DS01, Unit III
