hesim-dev / hesim

Health economic simulation modeling and decision analysis
https://hesim-dev.github.io/hesim/
62 stars 15 forks source link

Updating age and age bins in continuous-time simulation #113

Open mcincam100 opened 7 months ago

mcincam100 commented 7 months ago

Any progress on implementing ways to update age in a continuous time model? In my case I am modeling criminal justice trajectories, and the transition hazards vary over age bands (12-17 yo, 18-24 yo, etc.). Thus in my simulation I should have people transitioning between age bins, and therefore experiencing different hazards, as the time progresses. Can this be done now in hesim? I am thinking of something like this, but wanted to check if there have been any new functions that you've experimented with:

Update age and age category

for (i in seq_len(nrow(patients))) { sojourn_time <- data[i, "Tstop"] - data[i, "Tstart"] # Calculate sojourn time patients[i, "age"] <- patients[i, "age"] + sojourn_time patients[i, "age_category"] <- cut(patients[i, "age"], breaks = age_categories, labels = FALSE, right = FALSE)

Check if age has reached max_age

if (patients[i, "age"] >= max_age) { break # Stop the simulation for this patient } }