Tutorials › Introduction to Statistics › Sampling Categorical Outcomes With Unequal Probabilities

Simulation and Probability Models · Tutorial 379 of 996

Sampling Categorical Outcomes With Unequal Probabilities

Learn to build and verify cumulative intervals that assign uniform random numbers to categories with specified unequal probabilities.

Beginner 9 min read

What You'll Learn

  • Check that category probabilities are nonnegative and sum to one.
  • Convert a list of category probabilities into cumulative cut points.
  • Assign uniform random numbers using a consistent half-open interval rule.
  • Explain why each category receives its intended probability.
  • Handle zero-probability categories and boundary values correctly.
  • Verify a weighted-outcome mapping using interval lengths.

Why Unequal Outcomes Need Unequal Intervals

A simulation may need to generate outcomes that are not equally likely. For example, a hypothetical delivery model might assign a package to one of three routes with probabilities 0.20, 0.50, and 0.30. Giving each route one third of the possible random-number range would not represent that model: it would make all three routes equally likely. Instead, the routes must receive intervals whose lengths match their probabilities.

The basic idea is to start with a uniform random number between zero and one, then locate it in consecutive intervals. A category with a larger probability receives a wider interval and is therefore selected more often in the probability model. The method works for any finite set of categories, provided their probabilities are valid.

Definition: Suppose there are \(k\) categories, with probabilities \(p_1,\ldots,p_k\), where every \(p_i\geq 0\) and \(\sum_{i=1}^{k}p_i=1\). Define cumulative cut points \(c_0=0\) and \(c_i=\sum_{j=1}^{i}p_j\) for \(i=1,\ldots,k\). Given a uniform random number \(U\) on \([0,1)\), assign the outcome to category \(i\) when \(c_{i-1}\leq U<c_i\).

The categories must be placed in a fixed order before the cut points are calculated. The order is a bookkeeping choice; it does not change the probability assigned to any category, as long as each category is paired with its own probability consistently. The convention \([c_{i-1},c_i)\) includes the left endpoint and excludes the right endpoint. It assigns a value exactly on a cut point to the category immediately to its right.

Building and Reading the Intervals

To construct a mapping, list the categories and their probabilities, then add the probabilities from top to bottom. Each running total is a cut point. The first interval begins at zero, and the last interval ends at one because all the probabilities sum to one.

CategoryProbabilityCumulative cut pointUniform-number interval
Category 1\(p_1\)\(c_1=p_1\)\([0,c_1)\)
Category 2\(p_2\)\(c_2=p_1+p_2\)\([c_1,c_2)\)
Category 3\(p_3\)\(c_3=p_1+p_2+p_3\)\([c_2,c_3)\)
Category \(i\)\(p_i\)\(c_i=\sum_{j=1}^{i}p_j\)\([c_{i-1},c_i)\)

The interval for category \(i\) has length \(c_i-c_{i-1}=p_i\). That simple equality is the reason this procedure represents the intended probabilities. The next short justification makes the link explicit.

Why the Mapping Has the Intended Probabilities

A uniform random variable \(U\) on \([0,1)\) has the property that the probability of falling in any interval is the interval's length. The interval assigned to category \(i\) has length equal to \(p_i\), so the probability that the mapping produces category \(i\) is \(p_i\).

$$ c_i-c_{i-1} =\left(\sum_{j=1}^{i}p_j\right)-\left(\sum_{j=1}^{i-1}p_j\right) =p_i $$

Consequently,

$$ P(\text{category }i) =P(c_{i-1}\leq U<c_i) =c_i-c_{i-1} =p_i. $$

The intervals also cover the whole range without gaps or overlaps: the first starts at zero, each interval begins where the preceding interval ends, and the last ends at \(c_k=1\). Thus every possible \(U\) in \([0,1)\) is assigned to exactly one category. This proves both that the mapping is complete and that it gives each category its specified probability.

Worked Example: Mapping Three Outcomes

Suppose a hypothetical model has outcomes A, B, and C with probabilities 0.20, 0.50, and 0.30. Construct the intervals and assign the uniform values 0.08, 0.20, 0.69, 0.70, and 0.96.

Check the probabilities. They are nonnegative and sum to \(0.20+0.50+0.30=1.00\), so they form a valid probability distribution.

Calculate the cut points. In the listed order, \(c_1=0.20\), \(c_2=0.20+0.50=0.70\), and \(c_3=0.70+0.30=1.00\). The intervals are A: \([0,0.20)\), B: \([0.20,0.70)\), and C: \([0.70,1.00)\).

Assign the values. The value 0.08 is in A's interval, so it gives A. The value 0.20 is at A's excluded right endpoint and B's included left endpoint, so it gives B. The value 0.69 is also in B's interval. The value 0.70 is at B's excluded right endpoint and C's included left endpoint, so it gives C. The value 0.96 is in C's interval.

The resulting assignments are A, B, B, C, and C, respectively. The five assignments demonstrate how to apply the rule; their counts are not used to redefine the probabilities. In the probability model, the interval lengths are 0.20, 0.50, and 0.30, exactly the specified probabilities.

Worked Weighted-Outcome Example

Cumulative intervals are especially easy to verify when probabilities come from weighted equally likely slots. The weights determine how many slots belong to each category; dividing each weight by the total number of slots gives its probability.

Worked Example: A Spinner With Unequal Weights

Imagine a hypothetical spinner divided into 8 equally likely sectors: 1 sector is red, 2 are blue, and 5 are green. Use a uniform random number \(U\) to simulate the spinner, and assign \(U=0.10\), \(0.30\), \(0.80\), and \(0.99\).

Find the probabilities. The total weight is \(1+2+5=8\), so \(P(\text{red})=1/8=0.125\), \(P(\text{blue})=2/8=0.250\), and \(P(\text{green})=5/8=0.625\). These probabilities sum to \(0.125+0.250+0.625=1.000\).

Calculate the intervals. The cumulative cut points are \(c_1=0.125\), \(c_2=0.125+0.250=0.375\), and \(c_3=0.375+0.625=1.000\). Therefore, red receives \([0,0.125)\), blue receives \([0.125,0.375)\), and green receives \([0.375,1)\).

Assign the values. Since \(0\leq0.10<0.125\), \(U=0.10\) produces red. Since \(0.125\leq0.30<0.375\), \(U=0.30\) produces blue. Both 0.80 and 0.99 are at least 0.375 and less than 1, so they produce green.

Verify the mapping. The interval lengths are \(0.125-0=0.125=1/8\) for red, \(0.375-0.125=0.250=2/8\) for blue, and \(1-0.375=0.625=5/8\) for green. The intervals therefore encode the spinner's sector weights exactly.

Boundary Values, Zero Probabilities, and Precision

A value exactly equal to a cut point needs a stated rule. With the half-open convention used here, a cut point belongs to the interval that starts at that point. For instance, if the cut point is 0.375, then 0.375 belongs to the next category, not the preceding one. This convention is useful because it avoids assigning a boundary value to two categories or to none.

For an ideal continuous uniform random variable, any one exact value has probability zero. In particular, the chance of landing exactly on a specified cut point is zero. Nevertheless, software may generate values on a finite grid, so a consistent boundary rule remains important in an implemented simulation. A random-number generator that returns values in \([0,1)\) is compatible with the convention above. If a tool uses a different range or endpoint rule, adapt the interval rule to that range rather than assuming the endpoints behave identically.

A category with probability zero receives an interval of length zero. For example, if its cumulative cut points are both 0.40, its interval is \([0.40,0.40)\), which contains no values. Such a category can never be selected. A category with probability one receives the full range if it is the only category with positive probability.

When probabilities are reported as rounded decimals, their displayed values may fail to sum to exactly one. Before constructing intervals, determine whether the probabilities are exact or rounded. Use the underlying probabilities if available. If only rounded values are available, check their sum and state how the discrepancy is handled; do not silently let the last interval end above or below one. During calculation, retain adequate precision in cut points and round only when displaying results.

Common Mistakes and a Practical Check

A frequent error is to treat the cumulative cut points as the category probabilities. For example, if three categories have probabilities 0.20, 0.50, and 0.30, the cut points are 0.20, 0.70, and 1.00; the second category's probability is not 0.70. It is the length of its interval, \(0.70-0.20=0.50\).

Another error is to give every category the same interval width even though the probabilities differ. Equal widths would assign equal probabilities. The correction is to make each category's width equal to its own probability, as the cumulative-sum construction guarantees.

Before using a mapping, perform two checks: verify that the probabilities are nonnegative and sum to one, then verify that each interval's upper endpoint minus its lower endpoint equals the category's probability. These checks catch most mistakes in the table before any random values are assigned.

1
List the categories and probabilities.
Use a fixed category order and check that each probability is nonnegative.
2
Check the total.
Confirm that the probabilities sum to one; otherwise, the list does not define the intended probability distribution.
3
Compute cumulative cut points.
Starting from zero, add each probability in order until the final cut point is one.
4
Assign using half-open intervals.
For each \(U\), find the unique category with \(c_{i-1}\leq U<c_i\).
Key takeaway: To simulate unequal categorical probabilities from a uniform random number, assign each category a consecutive interval whose length equals its probability. Cumulative sums locate the boundaries, and a consistent endpoint rule makes every value assign to exactly one category.

Check Your Understanding

Try these questions before checking your notes.

  1. Categories A, B, and C have probabilities 0.15, 0.25, and 0.60. What are the cut points and intervals under the half-open convention?
  2. Using your intervals from question 1, which category is assigned to \(U=0.15\), and why?
  3. A category has probability 0.35 and is assigned the interval \([0.20,0.55)\). Verify that the interval has the correct length.
  4. Four outcomes have probabilities 0.10, 0.20, 0.30, and 0.30. What must be checked before using these values to construct intervals?
  5. Explain why a zero-probability category receives an empty interval.