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?
 A: As @DWin says in a comment, this is a standard application of survival analysis. That has the advantage of evaluating not only event occurrence but also the times to events.
If you do proceed with your train/test split (even 5000 patients might not be enough for that to be reliable; model evaluation by resampling might be better) you say that you have time-to-event data. In that case, even with an all-or-none logistic regression model, you can evaluate 28-day mortality by ignoring deaths that occur after 28 days from your start time.
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.
