How conditional probability, Bayes' theorem, and two supply chain causes — lead time and forecast error — can predict and prevent stockouts before they happen.
Every supply chain professional knows the pain of a stockout. Lost sales, eroded customer trust, expediting costs that eat into margins, and the ripple effect across downstream operations. Yet most organisations still approach stockout prevention with reactive, deterministic methods — fixed safety stock rules, static reorder points, and gut-feel adjustments.
What if, instead of reacting to stockouts after they happen, you could calculate the probability that a stockout will occur — and trace it back to its root cause — before it strikes?
This is where Bayesian statistics transforms supply chain planning from an art into a science. Using Bayes' theorem, we can take observable supply chain conditions (lead times, forecast errors) and compute the updated probability that a stockout is imminent — giving planners a precise, data-driven signal to act on.
In this real-world use case, we analysed 5 SKUs across 15 weeks of actual inventory data — tracking closing inventory, weekly orders, and two measurable causes that drive stockouts:
When supplier lead time exceeds 15 days, replenishment doesn't arrive in time to cover demand. Each week is coded as 1 (lead time > 15 days) or 0 (lead time ≤ 15 days). This creates a binary signal that Bayes can work with.
When the demand forecast deviates from actual demand by more than 30%, the ordered quantity is wrong — either too little (causing stockouts) or too much (causing excess). Again, coded as a binary 1/0 signal each week.
The prior probability is the baseline: how often does a stockout occur, regardless of any cause? This is simply the historical stockout frequency:
| SKU | Stockout Weeks | No Stockout | P(Stockout) | Risk Level |
|---|---|---|---|---|
| SKU1 | 8 | 7 | 53.3% | ⚠️ Medium |
| SKU2 | 8 | 7 | 53.3% | ⚠️ Medium |
| SKU3 | 11 | 4 | 73.3% | 🔴 High |
| SKU4 | 13 | 2 | 86.7% | 🔴 Critical |
| SKU5 | 8 | 7 | 53.3% | ⚠️ Medium |
But the prior alone is blunt. It tells us that stockouts are frequent, but not why. This is where Bayes' theorem adds a powerful layer.
The likelihood answers: how often does a specific cause appear during stockout weeks versus non-stockout weeks?
| SKU | P(LT>15 | SO) | P(LT>15 | No SO) | P(FE>30% | SO) | Dominant Cause |
|---|---|---|---|---|
| SKU1 | 37.5% | 28.6% | 25.0% | Lead Time |
| SKU2 | 50.0% | 42.9% | 55.6% | Forecast Error |
| SKU3 | 18.2% | 50.0% | 66.7% | Forecast Error |
| SKU4 | 61.5% | 50.0% | 80.0% | Both (Critical) |
| SKU5 | 25.0% | 71.4% | 37.5% | Neither dominant |
Now comes the power of Bayes. The posterior probability flips the question: given that we observe a long lead time right now, what is the updated probability of a stockout?
The denominator P(LT>15) is computed using the law of total probability:
| SKU | Prior P(SO) | P(SO | LT>15) | P(SO | LT≤15) | P(SO | FE>30%) | P(SO | FE≤30%) |
|---|---|---|---|---|---|
| SKU1 | 53.3% | 60.0% | 50.0% | 50.0% | 50.0% |
| SKU2 | 53.3% | 57.1% | 50.0% | 50.0% | 50.0% |
| SKU3 | 73.3% | 50.0% | 81.8% | 81.8% | 18.2% |
| SKU4 | 86.7% | 88.9% | 83.3% | 83.3% | 16.7% |
| SKU5 | 53.3% | 28.6% | 71.4% | 75.0% | 25.0% |
For SKU4: when lead time exceeds 15 days, the probability of stockout jumps from 86.7% to 88.9%. When forecast error exceeds 30%, the posterior is 83.3%. This SKU has near-certain failure under either cause — demanding immediate dual intervention on both supply reliability and demand planning.
SKU3 and SKU4 — Forecast error is the dominant driver. The posterior P(Stockout | FE>30%) jumps to 81.8% and 83.3% respectively. Action: Invest in ML-driven demand sensing, reduce forecast review cycles from monthly to weekly, and implement bias-adjusted safety stock.
SKU1 and SKU2 — Lead time is the primary lever. When LT>15 days, posterior rises above the prior. Action: Negotiate lead time SLAs with suppliers, establish dual-sourcing for critical materials, and implement lead time variability buffers in inventory models.
SKU5 — Counterintuitive finding: when lead time is long, stockout probability actually drops (28.6%). This suggests the planning team already compensates for known long lead times by ordering early. The real risk is when forecast error is high (75%). Action: The fix is demand planning accuracy, not supplier management.
Traditional safety stock formulas use standard deviation of demand and lead time to compute a static buffer. They treat all weeks, all causes, and all conditions identically. A Bayesian approach is fundamentally different:
1. It is conditional. Safety stock is the same every week. Bayesian probability changes based on observed conditions this week. If your supplier just notified you of a 20-day lead time, Bayes updates the risk in real time.
2. It identifies root causes. Safety stock tells you how much buffer to hold. Bayes tells you why you need it — and which lever to pull (supply reliability vs. forecast accuracy).
3. It enables differentiated action. Instead of applying the same safety stock policy to all SKUs, Bayes segments SKUs by their risk drivers. SKU3 needs forecast improvement. SKU1 needs supplier management. SKU4 needs both.
4. It learns. As new weeks of data arrive, the posterior becomes the new prior. The model continuously updates — getting sharper with every observation. This is the essence of Bayesian learning.
Phase 1 — Data Collection: For each SKU, track weekly closing inventory, orders, actual lead times, and forecast vs. actual demand. Code binary indicators: LT>15 = 1/0, FE>30% = 1/0, Stockout = 1/0 (closing inventory = 0 or negative).
Phase 2 — Prior Computation: Calculate the baseline stockout rate from historical data. Even 8–15 weeks of data is sufficient to establish a meaningful prior.
Phase 3 — Likelihood Estimation: Compute conditional probabilities for each cause given stockout and non-stockout weeks. This reveals which cause is the dominant driver per SKU.
Phase 4 — Posterior Updates: Apply Bayes' theorem weekly. When a new observation arrives (e.g., supplier confirms LT = 18 days), instantly update the stockout probability and trigger alerts if it exceeds a threshold (e.g., P > 70%).
Phase 5 — Automation: Embed the Bayesian model into your planning system or Excel dashboard. The computation is simple multiplication and division — no complex software required. Python, R, or even a well-structured spreadsheet can run this in real time.
Bayesian statistics is not a theoretical exercise — it is a practical, deployable tool that transforms stockout management from reactive firefighting into proactive, cause-driven optimisation. With just two binary signals (lead time threshold and forecast error threshold), supply chain teams can build a continuously learning system that answers the only question that matters:
Given what I observe right now about lead time and forecast accuracy, what is the exact probability that this SKU will stock out — and which cause should I fix first?
The mathematics is elegant. The implementation is simple. The impact on fill rates, working capital, and customer satisfaction is profound.
Supply chain optimisation is not about holding more inventory. It is about knowing where to look — and Bayes tells you exactly where.