Learn · Chapter 4

The uniform distribution

Discrete and continuous: when "all equally likely" is a fair model, and when it is not.

All values equally likely

The uniform distribution is the model for "no value is more likely than any other" within a range. It comes in two forms: the discrete uniform for the whole numbers from \(a\) to \(b\), and the continuous uniform for any value between \(a\) and \(b\).

The discrete uniform

Each of the \(b - a + 1\) whole numbers from \(a\) to \(b\) has the same probability:

A die is the discrete uniform from 1 to 6. A bookseller who sells between 90 and 100 books a day, every total equally likely, has 11 possible totals, each with probability \(\tfrac{1}{11} = 0.0909\). The mean is 95 books, the variance \(\tfrac{11^2 - 1}{12} = 10\) and the standard deviation 3.1623 books.

k = 96

P(X ≥ 96) = 0.4545

Open this set-up in the explorer
The bookseller: every daily total from 90 to 100 equally likely, with P(X ≥ 96) shaded

For a count the boundary matters. At least 96 books means 96, 97, 98, 99 or 100: \(P(X \ge 96) = \tfrac{5}{11} = 0.4545\). More than 96 leaves 96 out: \(P(X > 96) = \tfrac{4}{11} = 0.3636\). Fewer than 93 means 90, 91 or 92: \(P(X < 93) = \tfrac{3}{11} = 0.2727\).

A common mistake: a continuous model for a count

It is tempting to model the bookseller with the continuous uniform from 90 to 100: uniform.cdf(95, loc=90, scale=10) gives 0.5. But sales are whole numbers, and 6 of the 11 equally likely totals are 95 or fewer, so \(P(X \le 95) = \tfrac{6}{11} = 0.5455\). The continuous model loses the probability that sits on each whole number, and it cannot tell "at least 96" from "more than 95". Use a true discrete uniform, scipy's randint(90, 101), whose upper end is exclusive.

The continuous uniform

For a measurement that is equally likely to fall anywhere between \(a\) and \(b\), the density is flat at \(\tfrac{1}{b - a}\), and a probability is a length divided by the width:

A software team finds that fixing a bug takes anywhere from 1 to 5 hours, no time more likely than another: \(X \sim U(1, 5)\), with a density of \(\tfrac{1}{4} = 0.25\) per hour. The chance that a fix takes more than 4 hours is \(\tfrac{5 - 4}{4} = 0.25\), and between 2 and 3.5 hours \(\tfrac{1.5}{4} = 0.375\). The mean is 3 hours, the standard deviation \(\tfrac{4}{\sqrt{12}} = 1.1547\) hours, and 90 % of fixes take at most \(1 + 0.9 \times 4 = 4.6\) hours.

x = 4

P(X > 4) = 0.2500

Open this set-up in the explorer
Bug-fix time: a flat density of 0.25 per hour from 1 to 5, with P(X > 4) shaded

For a measurement the boundary makes no difference: \(P(X < 3) = P(X \le 3) = 0.5\), because a single point has no width and so no probability.

A density can be greater than 1

If fixes took between 1 and 1.5 hours, the density would be \(\tfrac{1}{0.5} = 2\) per hour. That is not a probability of 2: it is probability per hour, over a range half an hour wide, and the area under it is still \(2 \times 0.5 = 1\). That is why the axis of a density is labelled "density", never "probability".

Try this Squeeze the range in the explorer and watch the density rise above 1 while the area stays 1.

When "all equally likely" is not a fair model

  • Real sales cluster. Most shops have typical days and rare extremes. If the bookseller's records show many days near 95 and few at 90 or 100, the uniform overstates the extremes.
  • Ends that are not really ends. The uniform puts no probability outside \([a, b]\). If a bug can now and then take 8 hours, \(U(1, 5)\) says that never happens.
  • Schedules. The wait for a bus that comes every 10 minutes is uniform only for someone who arrives at a random moment; a commuter who knows the timetable waits less.
  • Where it fits: fair games of chance, random numbers (every simulation starts from \(U(0, 1)\)), and an honest "we know the range and nothing more".

In code

What it computes Python (scipy.stats) Excel
The bookseller: at least 96 books randint.sf(95, 90, 101) =(100-96+1)/11
The bookseller: fewer than 93 books randint.cdf(92, 90, 101) =(92-90+1)/11
The bug fix: more than 4 hours uniform.sf(4, loc=1, scale=4) =(5-4)/(5-1)
The bug fix: the 90th percentile uniform.ppf(0.9, loc=1, scale=4) =1+0.9*(5-1)

In scipy, randint(a, b + 1) is the discrete uniform from a to b, and uniform(loc=a, scale=b โˆ’ a) the continuous one. Excel has no uniform functions, so the formulas are the arithmetic itself.

Remember: The uniform spreads probability evenly: \(\tfrac{1}{b - a + 1}\) on each whole number, or a flat density of \(\tfrac{1}{b - a}\) over an interval. For counts, use the discrete uniform and read the boundary carefully (โ‰ฅ is not >). For measurements, a probability is a length over the width, and the density can be greater than 1.

Practise

Quiz

Three questions on the chapter. Your best score is kept in this browser.

1. Daily book sales are equally likely to be any whole number from 90 to 100. What is \(P(X > 97)\)?
2. Bug fixes take \(U(1, 5)\) hours. What is \(P(X = 3)\)?
3. A continuous uniform runs from 2 to 2.25. What is its density?
Answer every question first.
An unhandled error has occurred. Reload ๐Ÿ—™

Reconnecting…

Your connection to Introduction to Probability Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.