Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Probability for Decisions

Open In Colab

Probability for Decisions

Every morning the manager of the Olaya branch makes four small decisions before the first customer arrives: how many croissants to bake, how many baristas to put on the 8 o’clock peak, how many pre-ordered breakfast boxes to prepare, and (this autumn) whether opening half an hour earlier pays. None of the numbers she needs is known in advance. Tomorrow’s demand is not a number; it is a distribution.

This reading shows how to describe that uncertainty with three probability models (the normal, the Poisson and the binomial), how to simulate them with NumPy, and how to tell how much a small sample can be trusted with a confidence interval.

After this reading you can:

  • explain what a random variable and its distribution are, and why a decision needs more than the mean;

  • use the normal distribution to set a service level (how much to stock);

  • use the Poisson distribution for arrivals and the binomial for yes/no outcomes;

  • simulate a distribution with NumPy and check it against the formula;

  • explain sampling variability, the standard error and a 95% confidence interval, and use one to decide.

Textbook: Albright & Winston, Chapters 4–5 (probability and distributions) and 7–8 (sampling and confidence intervals), selected sections.

The data

One row per branch and day of 2025 (1,460 rows), with the counts behind the four decisions.

ColumnMeaning
date, weekdaythe day
day_typeworkday (Sunday to Thursday) or weekend (Friday and Saturday)
ramadan1 during Ramadan (1 to 29 March 2025), when mornings are much quieter
branch, citywhere
peak_customerscustomers who arrived between 8:00 and 9:00
croissant_demandcroissants customers asked for: sales, plus requests logged after a sell-out
box_preorders, box_pickupsbreakfast boxes pre-ordered in the app for that morning (paid at pickup), and boxes collected
early_customerscustomers between 6:30 and 7:00, counted only during the early-opening trial (Olaya and Corniche, 5 October to 9 November); empty otherwise
Loading...

Mornings differ by type of day: weekends and Ramadan are much quieter. A distribution only makes sense for days that are alike, so we keep workdays outside Ramadan and focus on the Olaya branch.

241 normal workdays at Olaya

1. From a number to a distribution

A random variable is a quantity whose value we will only know later: tomorrow’s croissant demand, the customers arriving between 8 and 9, the boxes collected. Its distribution lists the values it can take and how likely each one is.

  • A discrete random variable takes countable values (0, 1, 2 customers…); its distribution gives a probability to each value.

  • A continuous one can take any value in a range (a waiting time, a weight); its distribution is a density curve, and probabilities are areas under it.

Two numbers summarise a distribution: the mean (or expected value), the long-run average, and the standard deviation, the typical distance from it. Here is the croissant demand on 241 workdays at Olaya:

mean 121.8, standard deviation 19.1, from 61 to 176
<Figure size 700x340 with 1 Axes>

The mean, about 122 croissants, is the single best guess for tomorrow. But demand was below 100 on some days and above 160 on others. A decision taken on the mean alone ignores that spread, and the spread is what costs money: unsold croissants on quiet days, disappointed customers on busy ones.

2. The normal distribution: how many croissants to bake?

The histogram is roughly bell-shaped and symmetric. The normal distribution with the same mean μ\mu and standard deviation σ\sigma is a good model for it. Its main properties:

  • about 68% of values fall within μ±σ\mu \pm \sigma, about 95% within μ±2σ\mu \pm 2\sigma, and nearly all within μ±3σ\mu \pm 3\sigma;

  • any normal value can be turned into a z-score, z=(x−μ)/σz = (x - \mu) / \sigma, the number of standard deviations from the mean;

  • scipy.stats.norm gives probabilities: norm.cdf(x, mu, sigma) is P(X≤x)P(X \le x), norm.sf(x, mu, sigma) is P(X>x)P(X > x), and norm.ppf(q, mu, sigma) returns the value with a share qq below it.

within 1 sd: 69.3%   within 2 sd: 94.2%
<Figure size 700x340 with 1 Axes>

The data follow the rule closely (about 68% and 95%), and the curve fits the histogram. Now the decision. If the branch bakes exactly the mean, 122 croissants, it sells out whenever demand is above 122:

bake 122: model P(sell out) = 50%, in the data: 46% of days

Baking the mean means selling out on about half of all days (46% in the data, 50% in the model). The mean is a forecast, not a plan.

A better question is: on what share of days are we willing to sell out? That share defines a service level. To sell out on at most 10% of days, bake the 90th percentile of demand:

Loading...

Going from 50% to 90% service costs 25 extra croissants a day, and the data agree: with 147 croissants the branch sold out on 7.1% of days. Each further step costs more: 99% needs 167, 45 more than the mean. Which level is right depends on what a sell-out costs compared with a wasted croissant; Week 14 (the newsvendor model) answers that exactly. Today’s point: set the quantity from the distribution, not from the mean.

3. The Poisson distribution: staffing the 8 o’clock peak

Customers who walk in between 8:00 and 9:00 are counts of independent arrivals over a fixed period. When arrivals are independent and happen at a steady average rate λ\lambda, the count follows a Poisson distribution:

P(X=k)=e−λ λkk!,k=0,1,2,…P(X = k) = \frac{e^{-\lambda}\,\lambda^k}{k!}, \qquad k = 0, 1, 2, \dots

A Poisson variable has a special signature: its variance equals its mean. That gives a quick check on data:

mean 47.97, variance 46.72

The mean (48.0) and the variance (46.7) are close, so the Poisson model is plausible. The bars below show the data; the line shows the Poisson probabilities for λ=48\lambda = 48:

<Figure size 700x340 with 1 Axes>

One barista serves about 25 orders an hour at the peak. With 48 customers on average, two baristas (50 an hour) look sufficient. The distribution says otherwise:

Loading...

With two baristas, more than 50 customers arrive on 35% of workday mornings (the model and the data agree), so the queue builds about one morning in three. A third barista removes the problem almost entirely. A cheaper middle path, such as a helper who works only from 8:00 to 9:00, can now be compared on the same basis.

A trap: mixing different days. The Poisson model assumes a steady rate. Over all 365 days at Olaya, weekends and Ramadan included, the counts are a mix of several rates:

all days: mean 40.5, variance 166.1

The variance (166) is four times the mean (40.5). That is the sign of a mixture: fit one distribution per type of day, never one for the whole year.

4. The binomial distribution: how many breakfast boxes to prepare?

Customers can pre-order a breakfast box in the app and pay when they collect it. Each pre-order is a yes/no outcome: collected or not. When there are nn independent trials, each a success with the same probability pp, the number of successes follows a binomial distribution:

P(X=k)=(nk) pk(1−p)n−k,mean np,standard deviation np(1−p).P(X = k) = \binom{n}{k}\, p^k (1-p)^{n-k}, \qquad \text{mean } np, \quad \text{standard deviation } \sqrt{np(1-p)}.

First, estimate pp from the year’s pre-orders at Olaya:

share of pre-ordered boxes collected: 0.880

Tomorrow there are 50 pre-orders. If the kitchen prepares all 50, on average 6 boxes are never collected and thrown away. If it prepares fewer, a customer may arrive to find no box ready (it is then made on the spot, with a wait). The binomial distribution with n=50n = 50 and p=0.88p = 0.88 puts numbers on both sides:

collected boxes: mean 44.0, standard deviation 2.30
Loading...

If the manager accepts a wait on at most one morning in ten, she prepares 47 boxes: a customer waits on 5.1% of mornings, and on average 3.1 boxes are wasted instead of 6. The decision trades one risk against another, and the binomial distribution puts a number on each.

5. Simulating distributions with NumPy

Formulas exist for these three distributions, but most real problems combine several uncertain quantities, and then the easiest route is to simulate: draw many random values from each distribution and count what happens. NumPy’s random generator does this in one line per distribution. Fixing the seed makes the results reproducible.

sell out with 147 croissants: simulated 0.094   formula 0.093
overloaded with 2 baristas:   simulated 0.350   formula 0.350
a wait with 47 boxes:         simulated 0.051   formula 0.051

With 100,000 simulated mornings the shares match the formulas to two decimals. Simulation also answers questions the formulas cannot answer directly. With the plan 3 baristas, 147 croissants, 47 boxes, how often does something go wrong in a morning?

mornings with at least one problem: 14.0%

Each risk looks small on its own (9%, almost 0% and 5%), but together roughly one morning in seven has a problem. Week 14 builds whole decision models this way (Monte Carlo simulation).

6. Samples vary: the early-opening trial

From 5 October to 9 November (36 days), Olaya opened at 6:30 instead of 7:00 and counted the customers in that extra half hour. Opening early costs about 170 SAR a day (staff and utilities), and an early customer brings about 10 SAR of margin, so the branch needs 17 customers per morning to break even.

36 trial days, mean 18.31 customers, standard deviation 6.66

The trial averaged 18.3 customers, above 17. Should Olaya open early for good? The 36 days are only a sample of the mornings to come. Another 36 days would have given another mean. How much can a sample mean move?

We can see it with data we know completely. Treat the 241 croissant days of section 1 as the whole population, draw many samples of 36 days, and look at their means:

population mean 121.8
sample means: from 110.1 to 130.0, standard deviation 2.96
sigma / sqrt(36) = 3.17
<Figure size 700x320 with 1 Axes>

Three facts appear, and they hold for almost any population:

  1. Sample means scatter around the population mean: here from 110 to 130 croissants, around a true mean of 121.8.

  2. Their spread, the standard error, is σ/n\sigma / \sqrt{n}: 3.2 here (3.0 in the simulation, a bit less because each sample takes 36 of only 241 days). Four times as many days would halve it.

  3. Their histogram is bell-shaped. This is the central limit theorem: the mean of a large enough sample is approximately normal, whatever the shape of the data.

7. Confidence intervals: decide with the interval, not the point

A 95% confidence interval for a population mean, from a sample of nn values with mean xˉ\bar{x} and standard deviation ss, is

xˉ±t⋅sn,\bar{x} \pm t \cdot \frac{s}{\sqrt{n}},

where tt comes from the tt distribution with n−1n - 1 degrees of freedom (about 2.03 for n=36n = 36; it approaches 1.96 as nn grows). The method is built so that 95% of the intervals it produces contain the true mean. Check that with the croissant population: build an interval from each of 2,000 samples and count how many contain 121.8.

intervals that contain the true mean: 96.2%

About 95%, as promised (slightly more, again because the samples are drawn without replacement from a small population). Now the trial:

Olaya early customers: mean 18.31, 95% confidence interval [16.05, 20.56]
break-even: 17 customers

The point estimate (18.3) is above break-even, but the interval, 16.05 to 20.56, contains 17. The trial is consistent with an early hour that loses a little money as well as with one that earns a good margin. Its honest conclusion is not yet proven, not profitable.

The manager has three reasonable options: extend the trial, accept the risk because the downside is small (at worst about 1 customer a day below break-even), or try a cheaper set-up that lowers the break-even. What she should not do is report 18.3 as if it were certain.

How much longer? If the mean and standard deviation stayed at the trial’s values, the interval’s lower end would reach 17 when t⋅s/n≤18.31−17t \cdot s / \sqrt{n} \le 18.31 - 17:

about 100 trial days

About 100 days in all, almost three times the trial. Precision is expensive: halving the standard error takes four times as much data.

What a confidence interval does not say. It is not the range of daily counts (single trial mornings ranged from 5 to 38 customers); it is a range for the long-run average. And “95%” describes the method, not this particular interval: either it contains the true mean or it does not.

Summary

ModelUse it forQahwa House decisionKey result
Normala continuous quantity, roughly symmetriccroissants to bakethe mean (122) sells out on half the days; 147 for 90% service
Poissoncounts of independent arrivals at a steady ratebaristas at the peak2 baristas overloaded on 35% of mornings; 3 almost never
Binomialyes/no outcomes of nn independent trialsboxes to prepare47 boxes for 50 pre-orders: 5% risk of a wait, half the waste
Sampling, CIhow far a sample mean can be from the truthopen early?mean 18.3, but the 95% CI [16.05, 20.56] contains break-even (17)

In every case, the decision came from the spread of the distribution, not from its mean alone.

Next week: regression, a model that explains and predicts one variable from others.