Healthcare Capacity — Survival Meets Bed Planning
Python · lifelines, NumPyro, LightGBM · Data: UCI Diabetes 130-US hospitals (101,766 encounters, 1999–2008)
The Service Time, Earned Rather Than Assumed
The queueing example modelled the arrival side and took the service time as a given constant — three hours per patient, assumed. This one earns that number instead of assuming it, which closes the loop: a queue needs both how fast work arrives and how long it takes, and the second is a time-to-event problem.
The data is the UCI Diabetes 130-US hospitals file: 101,766 real inpatient encounters, with a mean length of stay of 4.4 days (capped at 14 in the source), 1.6% in-hospital mortality and 11.2% readmitted within 30 days.
Length of stay is a survival quantity, and treating it as an ordinary average throws away its shape. The event is leaving the bed; the Kaplan–Meier estimator gives the probability a patient is still occupying one after days without assuming any functional form. Median stay is 4 days. A Cox proportional-hazards model then asks which patients leave sooner, reaching a concordance of 0.689 — the probability that, given two patients, the model ranks the one who actually left first as the likelier to do so, where 0.5 is a coin flip and 1.0 is perfect. Better than chance, then, and nowhere near deterministic, which is itself the honest finding about predicting individual stays.
The direction of the coefficients is worth reading carefully, because the sign convention inverts intuition. The event being modelled is discharge, so a hazard ratio below 1 means discharge is slower — a longer stay. On that reading the drivers of long stays are number_diagnoses, number_inpatient and num_medications, all at 0.95: sicker, more complicated, more previously-admitted patients occupy beds for longer, which is clinically unsurprising and a useful check that the model is reading the data the right way round.
Two Ways To Leave A Bed
Not everyone leaves the same way. A patient who dies has not been "discharged later" — they have left the bed by a different route, and a naive survival curve that treats death as censoring quietly assumes they would eventually have been discharged. The correct object is the cumulative incidence function, which tracks each exit separately: by day 14, P(discharged alive) = 0.984 against P(died) = 0.016. For bed planning the distinction matters less than it does clinically — the bed frees either way — but getting it wrong would misstate the discharge curve, and the notebook shows both.
A parametric Weibull model fitted by MCMC adds the uncertainty a point estimate hides, and its shape parameter carries a fact about hospitals worth stating plainly. The posterior median is k = 1.71, and means the discharge hazard rises with days already spent: the longer a patient has been in, the more likely they are to leave on any given day. Length of stay is not memoryless — which is precisely the assumption the M/M/c queue next door makes about service times, and a good reason to check it rather than inherit it.
Readmission is the other half of clinical risk, and the result is a negative one reported as such: a gradient-boosted model reaches an AUC of 0.639 — the area under the ROC curve, the same ranking measure as concordance, on the same 0.5-is-chance scale — against an 11.2% base rate. That is weak. It is also consistent with the wider literature on readmission prediction, and it is more useful stated than buried — a model this uncertain can inform triage but cannot carry an individual discharge decision.
From Length Of Stay To Beds
The capacity link is the payoff, and it is arithmetic once the distribution is in hand. With mean stay 4.40 days and arrivals of 12 per day, mean occupancy is 53 beds — but planning to the mean fails half the time, and a 95% service level needs 65. The 12-bed difference is the same reserve that the grid buys as spare generation and staffing buys as spare nurses.
| bed requirement | beds | |
|---|---|---|
| mean occupancy | 53 | E[LOS] 4.40d × 12 arrivals/day |
| 95% service level | 65 | the 12-bed difference is the reserve |
| after a 10% cut in length of stay | 59 | saves 6 beds, 9% of the requirement |
And it turns the clinical question into an operational one. A 10% reduction in length of stay saves 6 beds — 9% of the requirement. That is the number a discharge-planning programme has to be worth, and it comes out of the survival model rather than a spreadsheet assumption.
Notebook
References
- Strack, B. et al. (2014). Impact of HbA1c measurement on hospital readmission rates: analysis of 70,000 clinical database patient records. BioMed Research International 2014, 781670. — the paper this dataset was released with
- Kaplan, E. L. & Meier, P. (1958). Nonparametric estimation from incomplete observations. JASA 53(282), 457–481. — the survival curve
- Cox, D. R. (1972). Regression models and life-tables. JRSS B 34(2), 187–220. — proportional hazards
- Fine, J. P. & Gray, R. J. (1999). A proportional hazards model for the subdistribution of a competing risk. JASA 94(446), 496–509. — why death is not censoring
- Green, L. V. (2006). Queueing analysis in healthcare. In Patient Flow: Reducing Delay in Healthcare Delivery, Springer, 281–307. — the bed-capacity link