Issue #2 · Use Case

Bayesian Statistics for Stockout Optimisation

How conditional probability, Bayes' theorem, and two supply chain causes — lead time and forecast error — can predict and prevent stockouts before they happen.

Krish Naidu · Mathnal Analytics April 2026 12 min read

The Stockout Problem Nobody Talks About

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.

The core question Bayes answers: Given that a supplier's lead time exceeded 15 days this week, what is the updated probability that this SKU will experience a stockout? And how does that change if the forecast error also exceeded 30%?

The Framework: Two Causes, One Outcome

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:

5
SKUs Analysed
15
Weeks of Data
2
Root Causes
150
Data Points

Cause 1: Lead Time > 15 Days

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.

Cause 2: Forecast Error > 30%

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.

Why these two causes? In supply chain theory, stockouts are fundamentally driven by two forces: supply-side failures (lead time) and demand-side failures (forecast accuracy). By isolating these two, we capture the primary levers of stockout risk.

Step 1: Compute the Prior Probability

The prior probability is the baseline: how often does a stockout occur, regardless of any cause? This is simply the historical stockout frequency:

P(Stockout) = Count of Stockout Weeks / Total Weeks Example: SKU4 had 13 stockouts in 15 weeks → P(Stockout) = 86.7%
SKUStockout WeeksNo StockoutP(Stockout)Risk Level
SKU18753.3%⚠️ Medium
SKU28753.3%⚠️ Medium
SKU311473.3%🔴 High
SKU413286.7%🔴 Critical
SKU58753.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.

Step 2: Compute the Likelihood (Conditional Probability)

The likelihood answers: how often does a specific cause appear during stockout weeks versus non-stockout weeks?

P(Lead Time > 15 | Stockout) = Count of (LT>15 AND Stockout) / Count of Stockout How likely is long lead time, given that a stockout occurred?
SKUP(LT>15 | SO)P(LT>15 | No SO)P(FE>30% | SO)Dominant Cause
SKU137.5%28.6%25.0%Lead Time
SKU250.0%42.9%55.6%Forecast Error
SKU318.2%50.0%66.7%Forecast Error
SKU461.5%50.0%80.0%Both (Critical)
SKU525.0%71.4%37.5%Neither dominant
Key Insight — SKU4: When this SKU experiences a stockout, there is a 61.5% chance that lead time was above 15 days AND an 80% chance that forecast error exceeded 30%. Both causes are firing simultaneously — this SKU needs urgent dual intervention.

Step 3: Apply Bayes' Theorem — The Posterior

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?

P(Stockout | LT > 15) = [ P(LT>15 | SO) × P(SO) ] / P(LT>15) Bayes' Theorem — updating prior belief with new evidence

The denominator P(LT>15) is computed using the law of total probability:

P(LT > 15) = P(LT>15|SO) × P(SO) + P(LT>15|No SO) × P(No SO) Total probability — combining both scenarios
Prior
P(SO)
Historical stockout rate
×
Likelihood
P(Cause|SO)
How often cause appears in stockouts
Posterior
P(SO|Cause)
Updated stockout probability

The Results: Posterior Probabilities

SKUPrior P(SO)P(SO | LT>15)P(SO | LT≤15)P(SO | FE>30%)P(SO | FE≤30%)
SKU153.3%60.0%50.0%50.0%50.0%
SKU253.3%57.1%50.0%50.0%50.0%
SKU373.3%50.0%81.8%81.8%18.2%
SKU486.7%88.9%83.3%83.3%16.7%
SKU553.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.

What the Posteriors Tell Supply Chain Leaders

SKU-Specific Action Plans

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.

The Combined Effect: When both causes fire simultaneously (LT>15 AND FE>30%), intersection analysis shows the probabilities compound. For SKU4, the combined intersection probability reaches 66.7% — meaning two-thirds of the time both causes are present, a stockout is virtually guaranteed. This is where safety stock alone cannot save you — you need root cause elimination.

Why Bayesian Beats Traditional Safety Stock

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.

Implementation: From Theory to Practice

Step-by-Step Deployment

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.

Python Implementation (simplified)
prior_so = stockout_weeks / total_weeks
p_lt_given_so = count_lt_and_so / stockout_weeks
p_lt_given_no = count_lt_and_no / no_stockout_weeks
p_lt = p_lt_given_so * prior_so + p_lt_given_no * (1 - prior_so)
posterior = (p_lt_given_so * prior_so) / p_lt

The Bottom Line

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.

More from Mathnal Insights

📐 15 Supply Chain Formulas Cheat Sheet 📊 Forecast Bias & Errors Guide 📦 Bayesian Stockout Optimisation ⚠️ 10 SC Risks 2026-2030 🔬 Free Inventory Diagnostic Tool 📈 Mathnal Product Suite 🎓 Training — Python, SQL, Power BI 🤖 AI-Literate SC Professional

Frequently Asked Questions

Everything you need to know
How is Bayesian statistics used in inventory management?
Bayesian statistics updates stockout probability based on observable supply chain conditions. The prior probability (historical stockout rate) is updated with likelihood data from causes like lead time exceeding 15 days or forecast error exceeding 30%. The posterior probability tells planners the exact probability of stockout given current conditions, enabling targeted intervention on the right root cause.
What causes stockouts in supply chain?
Stockouts are fundamentally driven by two forces: supply-side failures (lead time exceeding planned values, supplier disruptions, quality issues) and demand-side failures (forecast error, unexpected demand spikes, promotional under-planning). Bayesian conditional probability can quantify which cause is dominant for each SKU, enabling targeted corrective action.
What is a Bayesian safety stock model?
A Bayesian safety stock model updates the probability distribution of demand and lead time as new data arrives, rather than assuming fixed historical parameters. It starts with a prior belief, observes actual demand, and produces a posterior that adapts — so safety stock rises automatically when volatility increases and falls when demand stabilises, preventing both stockouts and overstock.
How do you calculate the probability of a stockout?
Stockout probability is the chance demand during lead time exceeds available inventory. With a demand distribution and lead-time distribution, P(stockout) = P(demand during lead time > reorder point). Bayesian methods refine this continuously as real demand is observed, giving a far more accurate figure than a static normal-distribution assumption.
What service level should I target to avoid stockouts?
It depends on the cost of a stockout versus the cost of holding inventory. High-value, high-criticality SKUs often justify 98-99% service levels; low-value, slow-moving items may only warrant 85-90%. The optimal level is where marginal holding cost equals marginal stockout cost. Mathnal's free Inventory Health Check computes this per SKU.
How does demand variability affect safety stock?
Safety stock scales with the standard deviation of demand and lead time — roughly proportional to the square root of lead time. Doubling demand variability does not double safety stock, but high-variability (XYZ 'Z') items require disproportionately more buffer. This is why segmenting by variability before setting buffers is essential.

📰 Latest from Mathnal Insights

Supply Chain Intelligence You Can't Afford to Miss

Issue #10 · Crisis Analysis

Iran-Israel-USA War: Quantified Supply Chain Impact & 12 Mitigation Strategies

Hormuz closure disrupts 20% oil, 34% helium, 46% urea. Brent +55%, freight +50%. Every route, cost & mitigation quantified.

Issue #9 · ESG & Scope 3

ESG Compliance & Scope 3: Genuinely Compliant or Exposed to Greenwashing Risk?

EU CSRD fines 5% revenue, UK CMA 10% turnover, 150+ US lawsuits. 6 regulations, 8 warning signs, 6-pillar compliance framework.

Free Tool · Interactive Simulator

Supply Chain Risk & Resilience Simulator (SCRRS)

Bayesian risk engine, 45 scenarios, Monte Carlo simulation, VaR/CVaR — simulate the Hormuz crisis on your supply chain.

View all 10 newsletters →  |  Free diagnostic tools →  |  CSCOP Certification →