This notebook provides a running example of estimating the following values, for a single patient:
Note: In the code, the constants denoting the states are named MILD, MODERATE and SEVERE. In the paper these constants correspond with the states named Moderate, Severe and Critical, respectively.
We shall provide estimates for a 55 year old male hospitalized in a critical condition. Predictions below are done from time of hospitalization but estimates can be predicted from any time since hospitalization.
Either MALE of FEMALE
sex = MALE
age = 55
Denoted as entry_state, this can be either MILD, MODERATE or SEVERE.
NOTE: in the paper, these are named MODERATE, SEVERE and CRITICAL respectively.
entry_state = SEVERE
For prediction from time of hospitalization this is necessarily the same as entry_state, but if we predict from some time during hospitalization this can be another state.
current_state = SEVERE
Integer number of days since hospitalization until the patient entered the current state
Examples:
For prediction from day of hospitalization (necessarily from first state) use: 0
If the patient was hospitalized for 10 days, 3 of them spent in the current state, then 7 days have passed since hospitalization until entry to the curent state, use: 7
days_since_hospitalization_until_entry_to_current_state = 0
Integer number of days spent at the current state
Examples:
For prediction from day of hospitalization (necessarily from first state) use: 0
If patient was hospitalized for 10 days, and is already 3 days in the current state, use: 3
days_at_current_state = 0
From the two definitions above we have:
total_days_since_hospitalization = days_since_hospitalization_until_entry_to_current_state +
days_at_current_state
SEVERE State:A binary 0/1 indicator of a past visit to the SEVERE state (In the paper: “Critical”). 1 indicates there was such a visit.
Note: if the patient was hospitalized in SEVERE state, the indicator should initially be 0, as there was no past visit to the SEVERE state.
was_severe = 0
covariates = construct_covariates(sex = sex,
age = age,
entry_state = entry_state,
cumulative_time = days_since_hospitalization_until_entry_to_current_state,
was_severe = was_severe)
This notebook computes 95% confidence intervals for the estimates listed above. Intervals are estimated using a weighted bootstrap based on 100 models, i.e 100 models each running 20K monte carlo simulations. This can be relatively slow.
Note: For estimates of the different quantiles of hospitalization time remaining and time remaining in a critical state, in estimates of extreme quantiles, coverage could possibly differ from 95%.
COMPUTE_CONFIDENCE_INTERVALS = TRUE
M_MONTE_CARLO_PATHS = 20*1000 # recommended
This is used to exclude outlier paths. For instance, this rule can be used to exclude occurences of paths longer than those observed in the data.
MAX_TRANSITIONS = 9 # recommended
monte_carlo_runs = israeli_model$run_monte_carlo_simulation(covariates,
to_model_state(current_state), # model uses a merged moderate/mild state
current_time = total_days_since_hospitalization,
n_random_samples = M_MONTE_CARLO_PATHS,
max_transitions = MAX_TRANSITIONS)
estimates = data.frame(estimate = t(compute_statistics(monte_carlo_runs)))
if (COMPUTE_CONFIDENCE_INTERVALS) {
bootstrap_sd = compute_sd_using_bootstrap(bootstrap_models,
covariates,
current_state,
total_days_since_hospitalization,
M_MONTE_CARLO_PATHS,
MAX_TRANSITIONS)
estimates["Standard Deviation"] = as.numeric(bootstrap_sd)
estimates["95%-lower"] = estimates$estimate - 1.96*as.numeric(bootstrap_sd)
estimates["95%-upper"] = estimates$estimate + 1.96*as.numeric(bootstrap_sd)
}
formattable(estimates)
| estimate | Standard Deviation | 95%-lower | 95%-upper | |
|---|---|---|---|---|
| probability_of_death | 0.135700 | 0.00541273 | 0.125091 | 0.146309 |
| probability_of_visit_to_severe_state | 1.000000 | 0.00000000 | 1.000000 | 1.000000 |
| time_hospitalized_remaining_quantile_0.1 | 8.000045 | 0.23866984 | 7.532252 | 8.467838 |
| time_hospitalized_remaining_quantile_0.25 | 16.000021 | 0.43239706 | 15.152523 | 16.847519 |
| time_hospitalized_remaining_quantile_0.5 | 28.000062 | 0.85244195 | 26.329276 | 29.670849 |
| time_hospitalized_remaining_quantile_0.75 | 44.000064 | 0.90431368 | 42.227609 | 45.772518 |
| time_hospitalized_remaining_quantile_0.9 | 47.000093 | 0.20000209 | 46.608089 | 47.392097 |
| time_remaining_in_severe_state_quantile_0.1 | 4.000041 | 0.49680951 | 3.026295 | 4.973788 |
| time_remaining_in_severe_state_quantile_0.25 | 8.000099 | 0.32951883 | 7.354242 | 8.645956 |
| time_remaining_in_severe_state_quantile_0.5 | 17.000087 | 0.44945990 | 16.119146 | 17.881028 |
| time_remaining_in_severe_state_quantile_0.75 | 29.000006 | 0.95190552 | 27.134271 | 30.865741 |
| time_remaining_in_severe_state_quantile_0.9 | 42.000019 | 0.90000228 | 40.236014 | 43.764023 |
plot_cdf_of_remaining_time_in_hospital(monte_carlo_runs)