Mean and standard deviation of a geometric random variable
If each try succeeds with the same small chance, how many tries does the first success take on average, and how far from that average does a single wait usually land?
Where you are 11 in Random variables
Why this exists
A yogurt brand prints a prize code under 1 in 25 lids, each lid independently of the others (made-up data, as is every number in this lesson). Thida opens lids one at a time until she finds a code. Her count of lids X is a geometric random variable with p = 0.04, and The geometric distribution already gives every probability: P(X = k) = (1 - p)^{k - 1}p and P(X > k) = (1 - p)^k.
That list has no end, so it does not answer the plain questions directly. How many lids does a search take on average? How much do searches differ from one another? The mean and the standard deviation would need an infinite table of products. For a geometric wait the whole sum collapses to two short formulas in p.
Definition
Let X be a geometric random variable with probability of success p on each trial, 0 < p \le 1, counting trials up to and including the first success. Its mean is the long-run average of X over many repetitions of the whole search,
and its variance \sigma_X^2 is the long-run average of (X - \mu_X)^2, weighted the same way. Its standard deviation \sigma_X is the square root of the variance, measured in trials.
Intuition
Picture a long row of lids, 10{,}000 of them. About p \times 10{,}000 = 400 carry a code. The searches split that row into about 400 stretches, each ending at a code, and together they use up all 10{,}000 lids. So a stretch averages \tfrac{10{,}000}{400} = 25 lids. Codes per lid is p; lids per code is \tfrac{1}{p}. This is the same long-run reading that gives a binomial count the mean np: in n lids expect np codes, so the lids per code is \tfrac{n}{np} = \tfrac{1}{p}.
The spread is large. Every bar in the graph is 0.96 times the bar before, so the tallest bar is the first and the bars fade slowly to the right. A few very long searches pull the mean up, and most searches end before 25 lids.
Results
For a geometric random variable X with probability of success p,
The mean and the standard deviation are measured in trials. The ratio \displaystyle \dfrac{\sigma_X}{\mu_X} = \sqrt{1 - p}, so when p is small the standard deviation is nearly as large as the mean.
Why it is true
The mean, by one more try. Look at the first trial. With probability p it succeeds and X = 1. With probability 1 - p it fails, one trial is used up, and because the trials are independent with the same p, the search starts over exactly as before. The trials still to come have the same distribution as X, so the average wait from there is 1 + \mu_X. Weighting the two cases by their chances,
Subtracting (1 - p)\mu_X from both sides leaves p\,\mu_X = 1, so \mu_X = \tfrac{1}{p}.
One honest note: solving for \mu_X treats it as a finite number. The second argument shows that it is.
The mean, by adding the tails. Write 2 \cdot P(X = 2) as P(X = 2) + P(X = 2), write 3 \cdot P(X = 3) as three copies, and so on, and stack the copies in rows. In the table P_k is short for P(X = k):
| row | k = 1 | k = 2 | k = 3 | total |
|---|---|---|---|---|
| 1 | P_1 | P_2 | P_3 | 1 |
| 2 | P_2 | P_3 | 1 - p | |
| 3 | P_3 | (1 - p)^2 |
The rows and columns go on forever. Column k holds k copies of P(X = k), so adding by columns gives \mu_X. Row j holds every P(X = k) with k \ge j, so it totals P(X > j - 1) = (1 - p)^{j - 1}. Every entry is positive, so adding the same entries in rows instead of columns gives the same total, and by the Infinite geometric series
The variance. The one-more-try idea works for X^2 as well. After a failure the wait is 1 + X', where X' has the same distribution as X, so the mean of X^2, written E(X^2), is
Expanding (1 + X')^2 = 1 + 2X' + X'^2, and using that the mean of a sum is the sum of the means,
so E(X^2) = \dfrac{2 - p}{p^2}. The variance is the mean of the square minus the square of the mean:
The honest note again: this treats E(X^2) as finite. A full proof sums the series \sum k^2 (1 - p)^{k - 1}p directly, which needs the calculus of power series. The shortcut “variance equals the mean of the square minus the square of the mean” is the expanded form of the weighted average of (X - \mu_X)^2 from Variance and standard deviation of a random variable.
Worked examples
Thida’s average search
Thida opens lids until she finds a prize code, with p = 0.04 for each lid, independently. Find the mean, variance and standard deviation of X, the number of lids she opens, and say what each means.
SolutionThe conditions for a geometric setting hold: each lid has a code or not, lids are independent, every lid has the same p = 0.04, and Thida stops at the first code. So
The variance is in squared lids, which has no plain meaning, so take the square root: \displaystyle \sigma_X = \sqrt{600} \approx 24.49, or \displaystyle \tfrac{\sqrt{0.96}}{0.04}, about 24.5 lids.
Over many searches like Thida’s, the number of lids averages 25, and a single search typically lands about 24.5 lids away from 25. A standard deviation almost as large as the mean says that searches vary a great deal.
Is 25 lids a typical wait?
For Thida’s lids, find P(X \le 25), the median wait, and P(X > 50). Explain why the mean is not a typical search.
Solution“At most 25 lids” is the complement of “the first 25 lids all fail”:
So about 64\% of searches end at or before the mean.
The median is the smallest k with P(X \le k) \ge 0.5, that is, 0.96^k \le 0.5. Trying values, 1 - 0.96^{16} \approx 0.4796, which is short of 0.5, and 1 - 0.96^{17} \approx 0.5004. The median wait is 17 lids.
Doubling the mean, P(X > 50) = 0.96^{50} \approx 0.1299: about 1 search in 8 takes more than 50 lids. These long searches make up the right tail of the graph. They pull the mean up to 25 while half of all searches are over by lid 17, so the distribution is strongly skewed right, and the most likely single value is X = 1. The mean answers “how many lids per code in the long run”, not “how long a search usually takes”.
Doubling the chance
For a summer promotion the brand puts codes under 2 in 25 lids. Aung searches with p = 0.08. Find the mean and standard deviation of his wait and compare them with Thida’s.
SolutionWith p = 0.08 and 1 - p = 0.92,
Aung’s mean wait is 12.5 lids, give or take about 12. Doubling p halved the mean exactly, because the mean is \tfrac{1}{p}. The standard deviation fell from about 24.49 to 11.99, a little less than half of what it was, because the factor \displaystyle \sqrt{1 - p} also shrank, from \displaystyle \sqrt{0.96} to \displaystyle \sqrt{0.92}.
Reading p from a mean
On a new flavor, the brand says a code takes 40 lids on average. Khin buys 200 of these lids for a club picnic. Find p, the standard deviation of a single search, and the number of codes Khin can expect among her lids.
SolutionThe mean is \tfrac{1}{p} = 40, so p = \tfrac{1}{40} = 0.025. Then
lids. The count of codes in 200 lids is a different variable: the number of lids is fixed, so it is a binomial count (The binomial setting) with n = 200, and its mean is np = 200 \times 0.025 = 5 codes. The two means fit together: 5 codes in 200 lids is 40 lids per code.
What a prize costs
Each cup of Thida’s yogurt costs 1.25 dollars. Let C = 1.25X be what she spends up to and including the cup with the first code. Find the mean and standard deviation of C.
SolutionC is X multiplied by the constant 1.25. Multiplying a random variable by a positive constant multiplies its mean and its standard deviation by that constant (Linear transformations of a random variable), so
On average a prize costs Thida 31.25 dollars of yogurt, and her spending typically differs from that by about 30.62 dollars.
Two separate searches
Thida and Aung each search on the regular lids (p = 0.04), separately and independently, until each has a code. Let T be the total number of lids they open. Find the mean and standard deviation of T, and say whether T is geometric.
SolutionT = X_1 + X_2, where X_1 and X_2 are each geometric with p = 0.04. Means always add, so \mu_T = 25 + 25 = 50. The searches are independent, so their variances add (Combining random variables):
The standard deviations do not add: 34.64 is less than 24.49 + 24.49. And T is not geometric. Its smallest value is 2, with P(T = 2) = 0.04^2 = 0.0016, while every geometric variable can equal 1.
Boundaries
- The geometric conditions. The formulas come from the one-more-try argument, which needs independent trials with the same p, so that a failure really starts the search over. If codes came in batches, or lids were drawn without replacement from a small box, the search would not start over and \tfrac{1}{p} would not be the mean.
- Which count. X counts trials including the success. The number of failures before it is Y = X - 1, so its mean is \tfrac{1}{p} - 1 and its standard deviation is unchanged.
- The ends of the range of p. With p = 1 every search ends on trial 1, so \mu_X = 1 and \sigma_X = 0. As p shrinks toward 0 both grow without limit, and at p = 0 no success comes and there is no mean.
- The mean is not the typical wait. The distribution is skewed right with its peak at X = 1, so in Thida’s case most searches end before the mean.
- Not a bell curve. The rule that most values fall within two standard deviations of the mean is for roughly symmetric, mound-shaped distributions. Here 25 - 2(24.49) is negative, so that reading tells nothing about short waits.
Where this goes next
These formulas are exact consequences of p. A simulation, as in Running a simulation and estimating a probability, estimates a mean wait by running many pretend searches, and Simulating a waiting time does that for waits that do not meet the geometric conditions. On the binomial side, Mean and standard deviation of a binomial gives the matching formulas np and \displaystyle \sqrt{np(1 - p)} for a count in a fixed number of trials. Both families are part of the study of Random variables.
Exercises
All data are made up. Round answers to two decimal places and probabilities to four.
The formulas
- A cereal brand puts a prize card in 1 in 20 boxes, independently. Find the mean and standard deviation of the number of boxes opened up to and including the first card.
- A geometric variable has p = 0.125. Find its mean, variance and standard deviation.
- Khin tosses a fair coin until it lands heads. Find the mean and standard deviation of the number of tosses.
- Aung rolls a fair number cube until it shows 6. Find the mean and standard deviation of the number of rolls.
- The first success takes 50 trials on average. Find p and the standard deviation.
- A geometric variable has variance 6. Find p and the mean.
- For Thida’s lids (p = 0.04), find P(X > 75), the chance of a search longer than three times the mean.
- For the cereal boxes of exercise 1, find the median number of boxes.
- For the cereal boxes of exercise 1, find the probability that the first card comes at or before the mean number of boxes.
In context
- Each cereal box of exercise 1 costs 1.60 dollars. Find the mean and standard deviation of the amount spent up to and including the box with the first card.
- With p = 0.125, let Y be the number of failures before the first success. Find the mean and standard deviation of Y.
- Aung and Khin each buy cereal boxes (p = 0.05), separately and independently, until each has a card. Find the mean and standard deviation of the total number of boxes.
- Brand A yogurt costs 1.00 dollars a cup with codes under 1 in 25 lids; brand B costs 1.30 dollars a cup with codes under 1 in 20 lids. Which brand gives a code for less money on average, and by how much?
- Thida and Aung open cereal boxes (p = 0.05) in rounds, one box each per round, independently, and stop after the first round in which at least one of them finds a card. Find the mean number of rounds and the mean number of boxes opened.
Reasoning
- Explain, without any algebra, why a code under 1 in 25 lids means 25 lids per code on average.
- Show that \displaystyle \dfrac{\sigma_X}{\mu_X} = \sqrt{1 - p}, and say what it tells about small and large values of p.
- Use the one-more-try argument directly on Y, the number of failures before the first success, to find its mean, and check that it agrees with \mu_X - 1.
- For the cereal boxes of exercise 1 the median is 14 and the mean is 20. Explain why they differ, and which one better describes a usual search.
- Thida has opened 30 lids with no code. She says: “I am due, so my remaining wait should be shorter than 25 lids on average.” Explain what is wrong.
- Add the tails P(X > 0) + P(X > 1) + P(X > 2) + \cdots for p = 0.5 and check that the total is \tfrac{1}{p}.
Answers
- p = 0.05: \mu_X = \tfrac{1}{0.05} = 20 boxes and \displaystyle \sigma_X = \tfrac{\sqrt{0.95}}{0.05} \approx 19.49 boxes.
- \mu_X = \tfrac{1}{0.125} = 8, \sigma_X^2 = \tfrac{0.875}{0.125^2} = 56, and \displaystyle \sigma_X = \sqrt{56} \approx 7.48.
- p = 0.5: \mu_X = 2 tosses and \displaystyle \sigma_X = \tfrac{\sqrt{0.5}}{0.5} = \sqrt{2} \approx 1.41 tosses.
- p = \tfrac{1}{6}: \mu_X = 6 rolls and \displaystyle \sigma_X = 6\sqrt{\tfrac{5}{6}} = \sqrt{30} \approx 5.48 rolls.
- \tfrac{1}{p} = 50, so p = 0.02 and \displaystyle \sigma_X = \tfrac{\sqrt{0.98}}{0.02} \approx 49.50.
- \tfrac{1 - p}{p^2} = 6 gives 6p^2 + p - 1 = 0, that is (3p - 1)(2p + 1) = 0. Only p = \tfrac{1}{3} is a probability, so \mu_X = 3.
- The first 75 lids all fail: P(X > 75) = 0.96^{75} \approx 0.0468, about 1 search in 21.
- Need 0.95^k \le 0.5. Since 0.95^{13} \approx 0.5133 and 0.95^{14} \approx 0.4877, the median is 14 boxes, below the mean of 20.
- P(X \le 20) = 1 - 0.95^{20} \approx 0.6415.
- \mu_C = 1.60 \times 20 = 32 dollars and \sigma_C = 1.60 \times 19.49 \approx 31.19 dollars (from the unrounded \displaystyle \tfrac{\sqrt{0.95}}{0.05}).
- Y = X - 1, so \mu_Y = 8 - 1 = 7, and subtracting a constant leaves the spread alone: \displaystyle \sigma_Y = \sqrt{56} \approx 7.48.
- Each search has mean 20 and variance \tfrac{0.95}{0.05^2} = 380. The total has mean 40 and, by independence, variance 760, so its standard deviation is \displaystyle \sqrt{760} \approx 27.57 boxes.
- Brand A: 25 cups at 1.00 dollars, 25 dollars. Brand B: 20 cups at 1.30 dollars, 26 dollars. Brand A is cheaper on average by 1 dollar.
- A round fails only if both boxes fail, 0.95^2 = 0.9025, so a round succeeds with p = 0.0975 and rounds form a geometric setting. Mean rounds \tfrac{1}{0.0975} \approx 10.26, and two boxes a round gives \tfrac{2}{0.0975} \approx 20.51 boxes.
- In a long run of lids about 1 in 25 has a code. The searches cut the run into pieces, one per code, that use up all the lids, so the pieces average 25 lids.
- \displaystyle \dfrac{\sqrt{1 - p}/p}{1/p} = \sqrt{1 - p}. For small p the ratio is close to 1, so waits vary about as much as their mean; as p nears 1 it nears 0, and almost every wait is 1.
- With probability p the first trial succeeds and Y = 0; otherwise one failure is counted and the search starts over. So \mu_Y = (1 - p)(1 + \mu_Y), giving p\,\mu_Y = 1 - p and \mu_Y = \tfrac{1 - p}{p}, which equals \tfrac{1}{p} - 1 = \mu_X - 1.
- The distribution is skewed right: most searches are short, but a few very long ones raise the mean, while the median ignores how long they are. The median, 14 boxes, describes a usual search; the mean, 20, describes boxes per card in the long run.
- The lids are independent, so the 30 failures do not change the coming lids. From lid 31 on the search starts over, exactly as in the one-more-try argument, and the mean remaining wait is still 25 lids.
- The tails are 1, 0.5, 0.25, \ldots, a geometric series with ratio 0.5, so the total is \tfrac{1}{1 - 0.5} = 2 = \tfrac{1}{0.5}.