zward / Amua

An open source modeling framework
GNU General Public License v3.0
32 stars 11 forks source link

Tunneling with Variables #45

Closed TJA87 closed 4 years ago

TJA87 commented 4 years ago

Hello,

Is there any way to associate variables with a specific Markov node?

I'm trying to create a tunneling effect where subjects will stay in a Markov node with changes in probabilities based on a table. This can be done, for example, with an age variable that starts counting at the first cycles (e.g. Age++ attached to any node seems to start this) and you could use this variable to look up the probability of death in a table. However, I'm wondering if there's a way to restart counting this variable in a new node once the model has started (e.g. do the same thing at a subsequent node X cycles into the model running). For example, if a subject went from being in remission to being in a category with metastatic disease, is there a way to advance a new variable.

Thanks!

zward commented 4 years ago

You could attach a variable update to the transition node (from the current state to the new state) that resets the variable to 0. For example, you could have a variable timeState which is updated at the Markov State every cycle: timeState++, and this could be reset when transitioning out of the state: timeState=0. (Actually, I think you'd want to reset it to timeState=-1 since it will be updated to 0 at the beginning of the next cycle by timeState++.) Would that approach work?

TJA87 commented 4 years ago

Thank you for the reply!

Variables aren't resetting for me. Here's a test model that just sets timeState=1 and doesn't respond to other variable commands within the model. timeState initially is equal to 1 and timeState is the reward for each transition node. Am I putting the variables in the wrong spot?

Thank you!

image

image

The timeState variable keeps increasing if I remove the timeState=0 from the model. I'd like this to happen again after the timeState=0.

image

(remove .txt at the end) timeState test.amua.txt

zward commented 4 years ago

Are you running the model as a Monte Carlo simulation? This type of variable tracking will only work with a microsimulation (i.e. Monte Carlo).

TJA87 commented 4 years ago

That worked! Thank you!

Is there any way to get a deterministic result with this type of simulation? (would I get a similar expected result as deterministic if my variables didn't have distributions (~)?)

zward commented 4 years ago

Monte Carlo is always stochastic in that it will always have first-order (individual-level) uncertainty (i.e. what happens to each individual in the simulation is stochastic). You can remove second-order (parameter) uncertainty by not including distributions in the parameters. (Variables with distributions would be considered first-order since they are sampled at the individual-level.)
You can seed the random number generator though (Model Properties -> Simulation -> Seed RNG) to get the same result each time you run the simulation, but this is still just one realization of a stochastic model.
To get more stable estimates you can increase the number of individuals (# of simulations in the Simulation tab). Or to characterize the uncertainty for a fixed sample size you can run Batch runs (not seeding the RNG) which will estimate the mean and 95% UI over N iterations of the model.

TJA87 commented 4 years ago

Monte Carlo is always stochastic in that it will always have first-order (individual-level) uncertainty (i.e. what happens to each individual in the simulation is stochastic). You can remove second-order (parameter) uncertainty by not including distributions in the parameters. (Variables with distributions would be considered first-order since they are sampled at the individual-level.) You can seed the random number generator though (Model Properties -> Simulation -> Seed RNG) to get the same result each time you run the simulation, but this is still just one realization of a stochastic model. To get more stable estimates you can increase the number of individuals (# of simulations in the Simulation tab). Or to characterize the uncertainty for a fixed sample size you can run Batch runs (not seeding the RNG) which will estimate the mean and 95% UI over N iterations of the model.

This info in amazing. Thank you!