3.2 Discrete Uniform Distribution ================================= 3.2.1 Main Idea --------------- The **discrete uniform distribution** applies when a random variable has a finite number of possible values and every value is equally likely. Suppose .. math:: X\in\{x_1,x_2,\ldots,x_n\} and all :math:`n` values are equally likely. Then .. note:: **Discrete Uniform Distribution** .. math:: P(X=x_i)=\frac{1}{n}, \qquad i=1,2,\ldots,n. The word **uniform** means that the probability is distributed equally over all possible values. A discrete uniform PMF therefore has the same probability height at every allowed value. The possible values remain separate points, but none is more likely than another. .. image:: ../_static/figures/discrete_distributions/figure_3_2_1_discrete_uniform_pmf.png :width: 68% :align: center :alt: Discrete uniform probability mass function with equal probability at the consecutive values from a through b. In the figure, each possible value receives the same probability :math:`1/(b-a+1)`. This equal-height pattern is the defining graphical feature of a discrete uniform distribution. 3.2.2 Example 1: Random Digit ----------------------------- Suppose one digit is selected at random from .. math:: \{0,1,2,\ldots,9\}. Let :math:`X` be the selected digit. There are .. math:: n=10 possible values and each is equally likely, so .. math:: P(X=x)=\frac{1}{10}, \qquad x=0,1,\ldots,9. The PMF therefore has the same height at every possible value. 3.2.3 Consecutive Integer Values -------------------------------- A common discrete uniform model uses consecutive integers .. math:: a,a+1,\ldots,b. The number of possible values is .. math:: n=b-a+1. Therefore, .. math:: P(X=x) = \frac{1}{n} = \frac{1}{b-a+1}, \qquad x=a,a+1,\ldots,b. The formulas for the mean and variance can be derived directly from this PMF. 3.2.4 Deriving the Mean ----------------------- For any discrete random variable, .. math:: E(X)=\sum_x x\,p(x). For a discrete uniform random variable on :math:`\{a,a+1,\ldots,b\}`, every value has probability :math:`1/n`. Therefore, .. math:: E(X) = \sum_{x=a}^{b}x\left(\frac1n\right) = \frac1n\sum_{x=a}^{b}x. To evaluate the sum, recall .. math:: 1+2+\cdots+m = \frac{m(m+1)}{2}. Hence, .. math:: \sum_{x=a}^{b}x = \left(1+2+\cdots+b\right) - \left(1+2+\cdots+(a-1)\right). Using the sum-of-integers identity, .. math:: \sum_{x=a}^{b}x = \frac{b(b+1)}{2} - \frac{(a-1)a}{2}. Substitute this into the expectation: .. math:: E(X) = \frac1n \left[ \frac{b(b+1)-(a-1)a}{2} \right]. Expand the numerator: .. math:: b(b+1)-(a-1)a = b^2+b-a^2+a. Factor: .. math:: b^2+b-a^2+a = (a+b)(b-a+1). Because .. math:: n=b-a+1, we obtain .. math:: E(X) = \frac{(a+b)n}{2n} = \frac{a+b}{2}. Thus, .. note:: **Mean of a Discrete Uniform Distribution** .. math:: \boxed{E(X)=\mu=\frac{a+b}{2}}. The mean is halfway between the smallest and largest possible values. This can also be interpreted as a balance point. Because all values carry equal probability weight, the loading is symmetric around the midpoint. .. image:: ../_static/figures/discrete_distributions/figure_3_2_2_uniform_mean_balance.png :width: 72% :align: center :alt: Equal probability weights at the values one through six balancing at the midpoint between three and four. For a fair die, the equal probability weights at :math:`1,2,3,4,5,6` balance at :math:`3.5`. The expected value does not need to be one of the possible outcomes; it represents the center of the probability loading. 3.2.5 Deriving the Variance --------------------------- For a discrete random variable, .. math:: \operatorname{Var}(X) = E(X^2)-[E(X)]^2. We already know .. math:: E(X)=\frac{a+b}{2}. Therefore, we first derive :math:`E(X^2)`. Because every value has probability :math:`1/n`, .. math:: E(X^2) = \sum_{x=a}^{b}x^2\left(\frac1n\right) = \frac1n\sum_{x=a}^{b}x^2. Recall the sum-of-squares identity .. math:: 1^2+2^2+\cdots+m^2 = \frac{m(m+1)(2m+1)}{6}. Therefore, .. math:: \sum_{x=a}^{b}x^2 = \left(1^2+2^2+\cdots+b^2\right) - \left(1^2+2^2+\cdots+(a-1)^2\right). Applying the identity gives .. math:: \sum_{x=a}^{b}x^2 = \frac{b(b+1)(2b+1)}{6} - \frac{(a-1)a(2a-1)}{6}. Hence, .. math:: E(X^2) = \frac{1}{6n} \left[ b(b+1)(2b+1) - (a-1)a(2a-1) \right]. Now substitute :math:`E(X^2)` and :math:`E(X)=(a+b)/2` into the variance formula: .. math:: \operatorname{Var}(X) = \frac{1}{6n} \left[ b(b+1)(2b+1) - (a-1)a(2a-1) \right] - \left(\frac{a+b}{2}\right)^2. Using :math:`n=b-a+1` and simplifying the algebra gives .. math:: \operatorname{Var}(X) = \frac{(b-a+1)^2-1}{12}. Since :math:`n=b-a+1`, this can also be written as .. math:: \operatorname{Var}(X) = \frac{n^2-1}{12}. Thus, .. note:: **Variance and Standard Deviation** .. math:: \boxed{ \operatorname{Var}(X) = \frac{(b-a+1)^2-1}{12} = \frac{n^2-1}{12} } and .. math:: \boxed{ \sigma = \sqrt{\operatorname{Var}(X)} }. 3.2.6 Example 2: Rolling a Fair Die ----------------------------------- Roll one fair six-sided die and let .. math:: X=\text{number shown}. Then .. math:: X\in\{1,2,3,4,5,6\}, so .. math:: a=1, \qquad b=6, \qquad n=b-a+1=6. Each value has probability .. math:: P(X=x)=\frac16. The PMF is flat because every die face is equally likely. .. image:: ../_static/figures/discrete_distributions/figure_3_2_3_fair_die_uniform_pmf.png :width: 58% :align: center :alt: Equal-height PMF bars for the six outcomes of a fair die. The six equal bars make the uniform assumption visible: changing the value of :math:`x` from 1 to 6 does not change :math:`P(X=x)`. **Mean** Using the discrete-uniform mean formula, .. math:: E(X) = \frac{a+b}{2} = \frac{1+6}{2} = \frac72 = 3.5. The same result can be checked directly from the PMF: .. math:: E(X) = \sum_{x=1}^{6}x\left(\frac16\right) = \frac{1+2+3+4+5+6}{6} = \frac{21}{6} = 3.5. **Variance** Using :math:`n=6`, .. math:: \operatorname{Var}(X) = \frac{n^2-1}{12} = \frac{6^2-1}{12} = \frac{36-1}{12} = \frac{35}{12} \approx 2.917. The same result can also be obtained from :math:`E(X^2)-[E(X)]^2`: .. math:: E(X^2) = \frac{1^2+2^2+3^2+4^2+5^2+6^2}{6} = \frac{91}{6}. Therefore, .. math:: \operatorname{Var}(X) = \frac{91}{6} - \left(\frac72\right)^2 = \frac{182}{12} - \frac{147}{12} = \frac{35}{12}. **Standard deviation** .. math:: \sigma = \sqrt{\frac{35}{12}} \approx 1.708. The expected outcome is 3.5. The standard deviation indicates that outcomes typically vary from this center by about 1.71 units. For example, .. math:: P(X\geq5) = P(X=5)+P(X=6) = \frac16+\frac16 = \frac13. 3.2.7 When Should We Use It? ---------------------------- Use a discrete uniform model when: - there is a finite set of possible values; - each possible value has the same probability. Typical examples include: - one fair die; - a randomly selected digit; - a randomly selected numbered tag; - one randomly selected integer from a specified finite set. Do not use a discrete uniform distribution merely because the possible values are equally spaced. Equal spacing does not imply equal probability. 3.2.8 Quick Practice -------------------- A box contains five tags labeled .. math:: 2,3,4,5,6. One tag is selected at random and each tag is equally likely. Let :math:`X` be the number on the selected tag. Find: (a) :math:`P(X=4)`; (b) :math:`P(X>4)`; (c) :math:`E(X)`; and (d) :math:`\operatorname{Var}(X)`. **Answer** There are five equally likely values, so .. math:: P(X=4)=\frac15. For :math:`X>4`, the favorable values are 5 and 6: .. math:: P(X>4)=\frac25. Here, .. math:: a=2, \qquad b=6, \qquad n=5. Thus, .. math:: E(X) = \frac{2+6}{2} = 4, and .. math:: \operatorname{Var}(X) = \frac{5^2-1}{12} = 2. 3.2.9 Common Mistakes --------------------- A common mistake is to assume that every discrete variable is uniform. For two coin tosses, the number of heads has possible values :math:`0,1,2`, but their probabilities are not equal. Another mistake is to count the integers from :math:`a` through :math:`b` as :math:`b-a`. Because both endpoints are included, the correct number is .. math:: n=b-a+1. When deriving the variance, do not forget that .. math:: \operatorname{Var}(X) = E(X^2)-[E(X)]^2, not :math:`E(X^2)-E(X)`. 3.2.10 Summary -------------- For a discrete uniform random variable on the consecutive integers .. math:: a,a+1,\ldots,b, there are .. math:: n=b-a+1 possible values, each with probability .. math:: P(X=x)=\frac1n. The mean is .. math:: E(X)=\frac{a+b}{2}. The variance is .. math:: \operatorname{Var}(X) = \frac{n^2-1}{12} = \frac{(b-a+1)^2-1}{12}. The standard deviation is .. math:: \sigma = \sqrt{\operatorname{Var}(X)}. The key modeling question is: Are all possible values equally likely?