Skip to content
Libellus
LibellusThe latest scientific discoveries, explained for everyoneFree · Independent · Not for profit · Translated in 5 languages
A gloved hand rests on a person's wrist over white bed linen, fingers positioned to feel the pulse.

Hospital Records Are Turned Into a Forecasting Engine That Can Simulate Future Care and Test Treatment Choices

13 min read

Electronic health records contain a long stream of measurements, notes, scans, and decisions made during hospital care. A machine-learning system trained on that stream treats each patient stay as one continuous sequence and asks what kind of event may come next, how much time will pass before it arrives, and whether changing an earlier treatment choice would alter the later course.

How a Hospital Stay Is Broken Into Events, Gaps, and Layered Predictions

A hospital stay is not one long record. It is a stream of small clinical events. A blood pressure check, a lab result, an X-ray order, and a discharge note all become separate items. Each item has several layers. The first layer asks what broad kind of event it is. The next layer adds specific details. Then the model decides which modality or value belongs to that detail. Timing comes from a hidden state rather than being guessed after every layer.

The layers are built in order. Later choices see earlier ones. That keeps predictions compatible. A lab result will not be paired with an impossible imaging type. At prediction time, the system blocks combinations it has never seen for that event type. Numbers are written in a compact wave-like code. The model can output new numbers in that same code. Its own generated events can then be fed back as input.

Time between events is also split into two questions. Many records share the same timestamp. One part asks whether any gap exists at all. Another predicts how long that gap lasts, but only when a real gap exists. If no gap is predicted, the answer is forced to zero. This avoids confusing “no time passed” with “a tiny amount of time passed.”

The model is trained to rebuild every part of an event. It also compares two versions of the same prediction. One version sees only past events. The other can peek at the current event. Early in training, that comparison is weak. Later it becomes stronger. This pushes the hidden state to carry real information about what comes next.

A second check uses only the past-based hidden state. It tries to reconstruct the real event from that state alone. This blocks two bad habits. The model cannot simply copy what it already sees and pretend it is certain. It also cannot hide behind vague, high-uncertainty guesses.

Hospital documentation is not evenly spread. Events are densest near admission. They thin out in the middle. They rise again before discharge. The variety of event types peaks at admission too. By late in a stay, care becomes more routine. Median gaps between different events grow longer. Early on they can be minutes long. Later they reach tens of minutes before leveling off.

Forecasting Future Clinical Events With or Without the True Clock

Forecasting a hospital future means guessing two things. One is what happens next. The other is when it happens. A model can be tested with or without the true clock. In free forecasting, it chooses both event type and timing. In time-controlled forecasting, the next event’s time is fixed by an outside schedule. This split shows how much accuracy comes from content versus timing.

The test starts 24 hours after a patient’s most recent admission. It then generates future events until it has used a fixed number of output tokens. Performance is checked at one, two, four, six, twelve, twenty-four, forty-eight, and seventy-two hours. Two baselines set the floor. One is a prevalence chance level. It just guesses what is common in the data. The other assumes recurrence. It says an event type or modality will return if it appeared in the same earlier window.

AUROC measures how well a model separates likely from unlikely events. A score of 0.5 would be random ranking. Scores near 1 mean strong separation. Brier score measures how close predicted probabilities are to outcomes. Free forecasting reaches macro AUROC values of about 0.75 to 0.83 for event types. For modalities, the range is about 0.76 to 0.82. These numbers span horizons from one hour to seventy-two hours. Macro AUROC treats each event type equally, so rare events matter as much as common ones. The Brier scores are generally much better than the persistence baseline. That baseline degrades badly over longer horizons.

When the model is given true timing, discrimination improves most at short horizons. At one hour, event-type AUROC reaches about 0.87 and modality AUROC about 0.95. By seventy-two hours, the advantage narrows. Free forecasting still has slightly better calibration for event-type counts even though its AUROC is lower. Calibration means predicted probabilities match observed rates.

At a fixed twenty-four-hour horizon, the test covers 13,551 patients. Free-forecast AUROC stays stable across stay-length groups. It is about 0.83 for short stays and about 0.84 for the longest stays. The Brier score rises only modestly, from about 0.084 to about 0.110. True timing improves discrimination at twenty-four hours. Time-controlled AUROC is about 0.86 to 0.87 across all groups, versus about 0.83 for free forecasting. But free forecasting has a better Brier score in the shortest stays. It is about 0.084 there, compared with about 0.096 under fixed timing. In longer stays, time-controlled forecasting has slightly better Brier scores.

Some events are easier to predict than others. Leaving the emergency department gets a free-forecast AUROC of about 0.98 at twenty-four hours. Leaving the ICU is close behind at about 0.97. Body output events reach about 0.96, and routine vital-sign or input events reach about 0.93. These are predictable because they follow regular care patterns. Documentation and administrative categories are harder. Radiology reports sit near 0.69, service changes near 0.70, transfers near 0.70, diagnoses near 0.71, and discharge summaries near 0.72. Lab tests are also hard to count precisely. The mean absolute error is about 13 events per patient over the window. Yet whether any lab test occurs at all has an AUROC of about 0.77.

The persistence baseline remains weak. Its event-type AUROC is about 0.58 to 0.63, and its modality AUROC is about 0.57 to 0.66. Its Brier scores worsen as the horizon lengthens. This means that simply repeating what happened before gives little useful signal. The model’s value comes from learning how event types, modalities, and timing interact over time.

Simulating an Alternative Sepsis Fluid Choice in a Virtual Patient Cohort

Sepsis care often starts with IV fluids. Saline and balanced crystalloids such as lactated Ringer’s are common choices. A virtual cohort test asked what would happen if each patient received the other fluid. It used 1,085 eligible episodes from a held-out set.

For each episode, two futures were generated. One kept the fluid actually given. The other swapped in the alternative. Random noise and timing were held identical. Later crystalloid administrations were forced to match the assigned arm. This isolated fluid choice from later treatment drift.

The simulated futures tracked three endpoints over 30 days. These were in-hospital death, length of stay, and a kidney outcome called MAKE-30. MAKE-30 combines new dialysis, death, or lasting kidney dysfunction. Ringer’s lactate looked better than saline on every main measure.

Across runs with defined outcomes, 30-day in-hospital mortality was about 44.9% under Ringer’s and 49.2% under saline. That gap was about 4.3 percentage points. Among simulations that explicitly ended in an outcome, the mortality gap widened to about 8.9 percentage points.

Length of stay was also shorter under Ringer’s: about 135.7 hours versus 174.3 hours. The difference was about 40.5 hours. This direction matches the sepsis subgroup of the SMART trial. In that real-world comparison, balanced crystalloid was associated with lower mortality than saline.

But the simulated absolute death rates are far higher than observed clinical rates. So the numbers need calibration before they can be read as real risks. The model’s own mortality forecasts were poorly calibrated in this cohort. Predicted risk ranged from about 3% to 96%. Observed risk in most deciles stayed between about 10% and 46%. The overall expected calibration error was about 27.7 percentage points.

The largest gaps appeared in middle-to-high risk groups. One decile had a predicted mortality of about 52% against an observed rate of about 16%. Another had a prediction of about 84% against an observed rate of about 26%. Only some simulations reached a final outcome within 30 days. About 68.5% did so under the matched arm and saline, while about 71.8% did so under Ringer’s lactate. The rest ran out of simulation budget before death, discharge, or a renal endpoint.

The kidney composite was mostly driven by death in the simulations. Observed MAKE-30 was about 27%, with death accounting for most of it. Simulated rates were much higher: about 75% under saline and about 66% under Ringer’s. The arm difference was almost entirely a mortality effect. Renal components changed by only about 0.1 to 0.2 percentage points.

This matters because the test is not just ranking fluids. It is checking whether a virtual patient model can reproduce a known clinical direction while exposing its own weaknesses. The fluid comparison pointed toward balanced crystalloid, as in real sepsis data. Yet the inflated death rates and weak calibration show that simulated outcomes are not yet ready for direct clinical use.

Reading Illness Severity and Survival Risk from a Single Patient Summary

A single encoded snapshot of a hospital record can be read in two ways. One readout turns it into an illness severity score. Another reads the risk that death will occur soon after that point. Both use the same compact summary, not separate raw charts. This matters because clinicians often need a quick sense of how sick someone is and whether their trajectory is dangerous.

The severity readout produces a continuous NEWS2-style score from 0 to 20. It tracks changes over each one-hour window. Its average error was about 1.34 points per hour. That is much better than guessing the average or median score, which made errors of about 2.8 to 3.0 points. Using age alone also gave an error near 2.8 points. A simpler linear readout on the same summary did slightly worse, with an average error of about 1.51 points. The neural readout was better at separating high-risk windows, with an AUROC of about 0.91 versus 0.89 for the linear model.

The score follows within-patient changes well. Its correlation with true one-hour scores was about 0.86. An age-only model reached only about 0.22. That means it can tell when a patient is getting worse or improving, not just how sick they are on average. The three standard risk bands were not all equally easy. Low-risk windows, scores of 0 to 4, were identified with high precision and recall, about 89% and 85%. Medium-risk windows, scores of 5 to 6, were much harder, with only about 39% precision and 41% recall. High-risk windows, score 7 or higher, were moderately well identified, about 69% precision and 72% recall.

The readout also has a predictable weakness. It compresses extremes. For mild true scores, it tends to predict slightly too high. For severe true scores, it predicts too low. The underestimation grows as severity rises, by several points when the true score is 10 or higher. The largest errors occur in rare very-high-score windows.

Survival risk was read from the same kind of summary using a time-to-event model called DeepSurv. Its hyperparameters were searched over standard ranges rather than fixed arbitrarily. As more of the stay became visible, discrimination improved. At admission, the C-index was about 0.76. Near the end of the stay, it rose to about 0.85. The integrated Brier score stayed low, around 0.021 to 0.024. Calibration tests did not flag significant miscalibration; all reported p-values were above 0.05 across five folds.

Which Parts of a Clinical Event Drive Surprise and Prediction

A clinical event is not just a label. It carries several layers of information. The broad type says what kind of record appeared. A lab result, an ECG, or a discharge note are different types. More specific details say which test was ordered or which diagnosis was written. Numeric values and images add the measured content. Timing records when the event happened in the stay.

Prediction depends on these pieces in an uneven way. Timing is usually the strongest clue to what comes next. A short gap after admission often points to routine checks. A long quiet stretch may suggest a change in care. Specific clinical text or category details are often second most important. Numeric and image values matter when the broad type is too generic. A lab result alone does not say much without its number. An ECG trace matters because the waveform carries rhythm information. A discharge summary can be hard to predict unless its text is known.

Surprise follows the same pattern. Routine measurements are easy for a model to expect. Vitals and lab tests sit near zero surprise, around 0.02 to 0.03 on the latent scale. Imaging events are far less predictable. The median surprise is about 38 for ECGs and 37 for X-rays. Echocardiograms are also hard, with a median surprise of about 22.5. Death is a special case. Its median surprise is low, about 0.96. But the upper tail is large. The 95th percentile reaches about 21.5, and the mean rises to about 4.24. In plain terms, death is not usually the most surprising event type. But when it occurs, prior context may make it hard to anticipate.

A Virtual Patient That Can Rehearse, But Not Yet Trust

A hospital record is not a pile of facts. It is a rhythm. One model has learned that rhythm well enough to do several hard things at once. It can guess what comes next. It can estimate how sick a patient looks. It can infer survival risk as the stay unfolds. It can even swap one treatment and replay the future.

That is the bigger picture. The value is not another dashboard number. The value is a virtual patient whose record can be probed before real decisions are made. Clinicians could ask what might happen if care changes early. They could compare fluid choices, watch severity drift, or test whether a rare event was predictable from context. This turns prediction into rehearsal.

The obstacles matter just as much. The model’s mortality estimates were badly miscalibrated in the sepsis fluid test. Some predicted risks sat far above observed rates. Simulated kidney outcomes leaned heavily on death rather than renal failure. Many futures ran out of tokens before reaching a clear endpoint. Medium-risk severity windows were hard to separate. Rare images and waveforms appear far less often than notes and lab values.

These limits are not small footnotes. They shape what can be trusted. A forecast that is directionally right but poorly calibrated can mislead. A virtual patient that cannot finish a 30-day story may miss the outcome that matters most. Data imbalance means the model knows routine care better than unusual care. Timing, documentation gaps, and event rarity all leave fingerprints on performance.

What comes next will need more than bigger models. It needs calibration that clinicians can rely on. It needs longer simulations with stable endpoints. It needs richer imaging data and clearer uncertainty signals. Prospective validation would test whether the virtual rehearsal matches real hospital life. If it does, the model could become a quiet tool for planning, not just scoring.

The deeper question is not whether machines can predict hospitals. They already do that in fragments. The harder question is whether they can learn enough to make uncertainty useful.

Keep reading

Continue to the next article

Continue to the next article

Continue to the next article