# How to model remaining hospital length of stay?

I am attempting to build a model which, for a patient currently admitted to the hospital, predicts the remaining amount of time until the patient is discharged.

Some of the predictors I'd like to use are patient-level (e.g. ethnicity), others are admission-level (e.g. admission diagnosis), and others can be entered many times at irregular intervals throughout the admission (e.g. temperature and blood pressure).

My first attempt was to build a model where each observation in my dataset was a single admission, using averages for the predictors which occurred multiple times throughout the admission, and the final length of stay as my dependent variable.

However, when I applied my predictions to the currently admitted patients, some patients had already exceeded their predicted length of stay by several days.

What would be the best way to build a model so that it predicts the remaining length of stay, given that the patient has already been in the hospital for a certain amount of time?

• This seems like classical survival analysis but it is actually not: except for the very recent data, none of your training data is actually censored (you exactly know when patients leave the hospital). Nevertheless a strategy like in survival forests might help: benkuhn.net/survival-trees. Essentially: treat each day of each patient as a new training sample and then use a classical ML classification algorithm as in the link or a regression algorithm trained on the remaining days... Commented Feb 12, 2018 at 22:58
• Also: what do you mean by “some patients had already exceeded ...”? You will never get a “perfect” algorithm/model. There will always be predictions that are wrong... Commented Feb 12, 2018 at 23:01
• Also: maybe the question you are asking is “wrong” in the sense that you actually want to know “how long should a patient stay at least in order not to become ill again after he/she has left the hospital?”. Then it is heavily survival like because every training data is censored. Commented Feb 12, 2018 at 23:05
• @FabianWerner Thanks! I guess I'm wondering how I explicitly account for the patient's current length of stay in predicting their remaining length of stay. For instance, I could include one row per patient-day with their remaining LOS as the dependent variable and the current LOS among the independent variables, but then how would I account for the lack of independence between the sequential observations for each patient? Commented Feb 12, 2018 at 23:40
• Have you thought of this as a chain? The patient is today in a state (in hospital) and has a probability of moving to a new state tomorrow (discharged, remains in hospital, dies) Commented Feb 13, 2018 at 9:43

First of all: on your initial model: The 'predict once at the beginning of the stay' model you built was not 'valid': Let us say that you have some data like this

PATIENT |       DATE | BLOOD_PRESSURE
A | 2000-01-01 |            100
A | 2000-01-02 |            120
A | 2000-01-03 |            110
...


and patient 'A' stayed for 3 days. Then on 2000-01-01 you would predict the patient by using the 'average' blood pressure of '110' but in reality, i.e. if a new patient comes in, then you do not know the average blood pressure the patient will have during his/her stay because most of his/er stay lies in the future.

Is this survival analysis? Depending on the question this is heavily survival analysis like or absolutely not survival analysis like. First we assume that the question actually is 'How long will the stay of the patient be?'. Then this is absolutely not a survival analysis task because for every patient in the dataset one knows exactly when the patient had his/her event (i.e. of leaving the hospital), there is no censored data whatsoever.

On the other hand, if the question actually is: 'What would be the minimal length of stay in the hospital such that the patient will not turn ill again?' (for example, one could ask that in order to save costs by treating patients only as long as it is really needed and no further) then every training data row is a censored row because we never knoe whath the 'ideal' length of stay would have been. All we can say for every stay is whether or not it was long enough (either the patient did not return soon because of the same disease [then it was long enough] or he/she did return [then it was too short]).

However, let us assume that the question is the first one: How long will the stay of the patient be?

Then the question is: When exactly do you need this information? Do you need this information when the patient arrives (then your only option is to build a 'predict once at arrival' model) or is it possible for you to make a first estimation and then continuously improve the prediction?

As stated: If you need a prediction st the point in time when the patient arrives then you must include all the information about the patient available at arrival (which kind of disease does the patient suffer from? How does the medical past of the patient look like? age, gender, ...) and you do not need to worry about the length of stay at all!

If you are able to continuously improve the prediction then you must worry about how to tell the model the 'evolution' of the stay (i.e. how has the blood pressure and the state in general developed during the stay? Is the patient getting better or worse?).

As stated in the comments: In this case I would recommend to start off with one row per patient per day like in the data table above and enrich that with much information like the length of stay until today, the mdeical past, etc. like so:

PATIENT |       DATE | BLOOD_PRESSURE | AVERAGE_BP_UNTIL_NOW | LOS | REMAINING_LOS
A | 2000-01-01 |            100 |                  100 |   0 |       2
A | 2000-01-02 |            130 |                  115 |   1 |       1
A | 2000-01-03 |            110 |                  113 |   2 |       0
...


The comment on that solution was:

I guess I'm wondering how I explicitly account for the patient's current length of stay in predicting their remaining length of stay. For instance, I could include one row per patient-day with their remaining LOS as the dependent variable and the current LOS among the independent variables, but then how would I account for the lack of independence between the sequential observations for each patient?

Let us first look at a very simple example: We want to predict the remaining years a human being has to live. In our imaginary universe, people usually die in the age of 100. Again, you could build two models: Predict the remaining years for a human being once or: predict the remaining days every day. Let us inspect the second case and let us consider two members: one being that we start to observe in the age of 20 (will turn 90 before death) and one that we start observing at the age of 80 (will turn exactly 100). Then the training set will look something like this (forgive my bad drawing style):

black dots = the member that we observe for many years

red dots = the member that we observe for only a few years

green line = the perfect regression line

The linear regression line that we will learn will be lower than the green line simply because it seeks to minimize the error to all points and since we have more black points than red points, it will come close to the black ones.

What I want to say is: Even a model that has some precise probabilistic description does not completely break down just because you violate these assumptions 'a little'. The learnt regression line would still be close to the perfect one (in the sense that it is not completely off). The probabilistic models of other models/learning algos (SVM, Gradient Boosting) are complicated intrinsically and I dont even know whether they demand / one can precisely describe what happens if not the examples are independent. From experience I can only say that I have happily trained Gradient Boosting models with this repeating pattern [not caring at all about independence] and they performed well.

In one sentence: Its better to try out a completely new 'continous instead of predict only once' model and get a little worse performance but see whether the new philosophy (of predicting the patient multiple times) gives a huge improvement or not than to just 'not do it' because one is afraid that the performance is not the best possible.

In any case: Should the continuous model turn out to be better the one could avoid the effect mentioned above by just 'weighting' the examples by 1/(length of stay) [in the loss function for example] in order to normalize them.

Also: If you want to train a "continuous model" then you must give the model the chance to deduct something about the length of stay from the 'development' / 'evolution' of the patient during his/her stay, i.e. allow it to see that 'if the blood pressure very suddenly changes rapidly then something is really wrong with the patient and he/she must stay for a long time'. You cannot do this without giving the model the ability to

a) see what the usual blood pressure was until now

b) make it able to see rapid rise/fall in blood pressure

• This is extremely helpful, so thank you for taking the time to craft such a thoughtful response. To answer your questions: you're correct in assuming I care about how long the patient's stay will be, not how long it should be, and I do want the prediction to update over the course of the patient's stay based on new information. Just to clarify: with the approach you've suggested, I would not include in my training set any indication that two rows "belong" to the same patient, correct? I'm going to retrain the model using this 1 row per patient per day approach! Commented Feb 13, 2018 at 18:18
• I have not seen a situation so far where things like “telling the model that the are the same patient” are helpful. The reason, I believe, is the following: the mode should learn general relations like “if the blood pressures look like this and that then the stay will be longer”. Any reference to the concrete patient would be overfitting. I would nevertheless couple the values in the sense mentioned above: maybe take the aberage blood pressure of that currently considered patient as a feature. That is something “unique” for that patient without making an actual reference to the patient itself. Commented Feb 13, 2018 at 18:34

There are two separate issues here.

However, when I applied my predictions to the currently admitted patients, some patients had already exceeded their predicted length of stay by several days.

Unless I'm misunderstanding, this reflects the lack of fit of your model. Had it been perfect this residual would tend towards 0; the extent of these differences between real and predicted are wrapped up in your sum of squared error you seek to minimize.

What would be the best way to build a model so that it predicts the remaining length of stay, given that the patient has already been in the hospital for a certain amount of time?

This appears to be an issue related to how you report the output. The model (again, as I understand it) yields total length of stay, so if you want a predicted remaining stay, you'd subtract the current stay from predicted total.

• With my current approach, I am reporting remaining length of stay as the difference between the predicted and the current length of stay, but it's clear to me what prediction should be made when the current LOS already exceeds the predicted value. Would there be a way to modify the model that explicitly takes into account the amount of time the patient has already stayed? Commented Feb 12, 2018 at 23:48
• Probably not during training. Doing so would likely hurt the model because it's unrelated to the overall relationships...you could build it in to your overall script, say right after your 'predict' call Commented Feb 13, 2018 at 1:45