Page 1 of 1

Stock behaviour difficult to understand

Posted: Mon Jul 07, 2025 3:08 pm
by Ashish_Kumar
I attach my WIP model, data file (synthetic data), and a results file. In the "CH" view, top right, the stock "CH Patients" has only one inflow, "CH Admissions by case mix and age group", and one outflow, "CH Discharges".

As shown in the results file, for the selected subscript values:
- At time 13: the first admissions happen. There are 7 admissions.
- At time 14: 3 more admissions happen. There are no discharges yet. But, the stock "CH Patients" decreases to 6.5.
Why is this happening?

(There are hidden links to CH Patients to set the initial value of the stock).

Re: Stock behaviour difficult to understand

Posted: Mon Jul 07, 2025 4:17 pm
by Administrator
First thing, when debugging a model, make sure the save period (saveper) is the same as time step. You can do this by editing the equation for saveper, or clicking Model->Settings->Time bounds and ticking "Save results every time step".

You are almost certainly missing results as you are not saving everything.

Re: Stock behaviour difficult to understand

Posted: Tue Jul 08, 2025 4:54 am
by Ashish_Kumar
Noted, thanks.

The problem doesn't change when I see results every step, though. The inflow, stock, and outflow don't tally.

What I am trying to do is model inflow as a function of patients transferred to community hospital from acute hospital, constraining inflow to be an integer. Outflow is calculated with DELAY FIXED, based on the length of stay, with a check that outflow does not exceed the stock value. A multiplier is applied to both inflow and outflow to reflect variation in activity by day of week (lower during weekend, higher on Mondays and Fridays etc.)

Re: Stock behaviour difficult to understand

Posted: Tue Jul 08, 2025 5:38 am
by Administrator
It's important to try and understand how levels/rates are calculated and used in Vensim.

stock (time) = stock (time-time step) + sum of rates * time step

Given you have a small time step, the value of "CH Patients" increases slowly.

Do you need to add all 7 patients into the "CH Patients" stock in a single time step?

Re: Stock behaviour difficult to understand

Posted: Tue Jul 08, 2025 6:20 am
by Ashish_Kumar
Thanks. For the benefit of others, I found this useful when I went through it last year:
https://www.youtube.com/watch?v=6pvJhKA0BmU

In this case, part of the model is discrete (I also have another post about the same model; I thought the two topics were not related:)). I do need the 7 patients (or whatever the number is) to get in in one time step. I realised one way to do this is have time-step = 1.

In any case, the solution will come from aligning the stock equations so that they account for the the form you've written above. E.g., I guess I could use the INTEG equation in my stocks with 1/ TIME STEP.

Re: Stock behaviour difficult to understand

Posted: Fri Jul 11, 2025 12:15 am
by tomfid
You might also check out this:
https://vensim.com/video/#DS1_Discrete_Events