# How to calculate 28 day mortality?

I have a retrospective EHR database from a hospital and I would like to build an ML model to predict whether a patient will die within 28 days or not (from discharge/some time point T)

Can I check with you on the below steps?

a) Let's say I have a sample of 5000 patients

b) I choose training data as 3500 patients

c) For these 3500 patients, I extract the required variables and their values till time "T"

d) And now for training data, we need labels, So I calculate using a python script whether this person has died within 28 days from time "t" (because I have all their data. I can find the difference between his discharge date and death date)

e) If yes, I will label it as "1" else "0"

f) I build a supervised learning model using logistic regression

Now comes the challenging part (for me atleast)

g) I would like to apply this model on the unseen set of 1500 patients

h) I extract the same variables as training data

i) Now I apply the model to this unseen data of 1500 patients

k) But the problem is this will only give whether the patient will die or not. How can I know whether he will die or not in the 28 days?

How can I incorporate this time component here.

Can somebody help me with this by providing easy to understand steps and which algorithm to use please?

• Why not do survival analysis? – DWin Nov 25 '20 at 0:49
• @DWin - Can survival analysis help in prediction as well? Sorry, not done much with survival analysis before...will read up online... Any other ML algorithms that can help? – The Great Nov 25 '20 at 1:24
• Indeed survival analysis can predict. There are many flavors of survival analysis. The survival package in R is a "recommended package, but there are also alternatives. I use both survival and rms. There's a well supported eha (event history analysis) and more recently the flexsurv package has become available. There is also a random survival forest package if you wnat to stay on the "data science" side of mythology (ooops, that was what my spell-chucker offered and it amused me) and don't want to stray into "real statistics". – DWin Nov 25 '20 at 4:04
• LSTMs can work for such problems? – The Great Nov 25 '20 at 10:32

The rms package in R, also noted by @DWin, provides a well developed infrastructure for combining survival analysis with resampling-based model validation and calibration, and providing predictions for specified combinations of covariate values. There's no reason why the approaches used there can't be extended to analysis with more of a "machine-learning" or "data-science" flavor. Just be aware that models provided by those latter approaches can be harder for mere human beings to interpret.
• @TheGreat it's certainly OK to focus only on things like 28-day or 30-day mortality if you don't care about the actual times to events. If you do care about times to events, it's possible to use methods like those in your cited paper to evaluate survival models, too. For example, the R xgboost package allows for Cox and accelerated failure time survival models. Your choice comes down to whether or not you care about times to survival or only about yes/no survival up to a particular cutoff time. – EdM Dec 17 '20 at 15:50
• Hi @EdM - Q1) Am a bit confused. Isn't focusing on things like 28-day or 30-day mortality called Time to Event analysis? Because based on your comment - it's certainly OK to focus only on things like 28-day or 30-day mortality if you don't care about the actual times to events, am I incorrect to understand that predicting 28 day or 30 day mortality is Time to event analysis? May I know why isn't that called as 'Time to event' analysis – The Great Dec 18 '20 at 16:00
• Would you mind to help a noob like me to understand the difference/elaborate your comment - Your choice comes down to whether or not you care about times to survival or only about yes/no survival up to a particular cutoff time with an example please? I thought both that you mentioned are time to event analysis and there is no difference between them. But looks like there is some difference – The Great Dec 18 '20 at 16:02
• @TheGreat yes, you have it right. If it's just survival up to some time, without reference to the actual time during that interval, then it's a classification (better, event-probability) task. If you want to model the actual time until an event, then it's a survival model. Besides survival:cox, the R implementation of xgboost (at least) also provides an accelerated-failure-time objective function (survival:aft) for survival models. – EdM Dec 20 '20 at 18:43