Simulation
Medicine supply digital twin (1/14): forecasting demand with Holt-Winters
The start of a 14-part series on a digital twin of medicine supply in a public health system. First piece, the forecast. Level, damped trend and weekly season, with every formula worked by hand.
A prescription that goes unfilled almost never fails at the pharmacy. It fails weeks earlier, when someone decided how much to order using a number that no longer matched reality. That is why I built a digital twin of medicine supply: a software copy of the whole chain, from the annual plan to the moment the patient gets the medicine, to test decisions before making them.
This series walks through that twin in 14 posts. The setting is a fictional public health system: a central warehouse, regional warehouses, and primary and secondary care units. The data is simulated; the models and the math are the ones the twin uses, and every post comes with an interactive aid to move the parameters.
| # | Module | Question |
|---|---|---|
| 1 | Forecast | How much will be used? |
| 2 | Safety stock | How much buffer is needed? |
| 3 | Central warehouse policy | Min-max or forecast? |
| 4 | Allocation | If there isn’t enough, who gets what? |
| 5 | Routes | How to deliver with fewer kilometres? |
| 6 | Docks | How many docks so there is no queue? |
| 7 and 8 | Cold chain | How long does a fridge last? Who notices a failure? |
| 9 and 10 | Procurement and contracts | Whom to buy from? What if they don’t deliver? |
| 11 | Physical inventory | How often to count? |
| 12 | Last mile | How does it reach the patient? |
| 13 | Plan integrity | Which data prevent manipulation? |
| 14 | Control tower | Where in the chain is the failure? |
Today’s piece: the forecast
Everything else depends on knowing how much will be used. Demand for one item at one unit has three parts that can be separated:
- a level: what is used on a typical day;
- a trend: whether that level is going up or down;
- a season: the weekly pattern. More prescriptions are filled on Mondays than on Sundays.
The Holt-Winters method tracks all three at once. Each day it compares what it forecast with what happened and nudges each part a little. How much it nudges is set by three numbers between 0 and 1: , and .
The three equations
Each one is a weighted average of what the new data says and what was believed before:
- The level takes today’s demand without the day effect () and blends it with what it expected.
- The trend blends the level change it just saw with the one it had.
- The day effect compares demand with the level and updates that weekday’s value.
And the forecast puts the three together:
Why damp the trend
Without damping (), a trend of one unit per day is projected forever: in 90 days the forecast would rise by 90 units. With medicines that rarely happens; increases level off. With the trend sum converges:
So however far ahead you forecast, the current trend never adds more than about 32 units. In the first week, on the other hand, it barely shows: against 7 undamped.
How α, β and γ are chosen
They are not guessed: they are validated. The twin trains the model on every day except the last seven, forecasts that unseen week and measures the error with WAPE:
It tries 12 combinations (, , ) and keeps the one with the lowest error.
The uncertainty band
A forecast without uncertainty is misleading. The twin computes the deviation of the fitting errors and draws an 80 % band that widens with the horizon:
1.28 leaves 10 % probability above and 10 % below in a normal distribution. The factor growing with is a practical rule: the error of forecasting four weeks out is larger than tomorrow’s. In the aid’s series, with units, the band goes from units tomorrow to four weeks out.
Try it: move , and , watch the error on the test week (orange line) and then let the button pick by validation.
The twin’s state network on the Forecast tab (“Pronóstico”): each unit’s demand runs in simulated time. (Interface in Spanish.) · Open full screen
What this forecast doesn’t see
Holt-Winters only looks at the item’s history. It doesn’t know the respiratory season is coming, that a new service opened or that last week there was a shortage and “real” demand stayed hidden. Two details of the twin help with that: demand is counted as filled plus denied, so a shortage doesn’t look like a drop in use, and the forecast interface is the same one a machine-learning model with weather, epidemiology and calendar data would use. Swapping the engine changes nothing downstream.
What comes next
A forecast is a number with uncertainty. The next post turns that uncertainty into units: how much safety stock is needed to fill 95 % of the time, and why an unpunctual supplier weighs more than variable demand.