# Transitioning states at intervals longer than stage length in Markov model

I am trying to create a model that has a stage length (3 months) which is shorter than how someone would remain in a stage (ie monitoring for 3 years and then testing). I originally created a tracker for each time in monitoring stage and created a table for based on tracker number for probability of testing (basically index 1-11 have value of 0, while 12 has value of 1). To simplify this, is it possible to use an if(condition;trueval;falseval) statement such as if (tracker<12;0;1) as the definition for the variable which will represent the probability (ie pTesting = if(tracker<12;0;1))

Thanks

### Comments

7 comments
• You can definitely use the syntax you suggested.

pTesting = if(tracker<12; 0; 1)

When tracker is 0 - 11, pTesting = 0

When tracker is greater than 12, pTesting = 1

You will need to consider resetting the tracker too if someone can repeat the "monitor-testing" cycle. So when they move to Testing, set tracker = 0. Then when they cycle back through the monitoring phase (which increments the tracker each cycle) you will test at the correct intervals.

• Great. So at the “testing” state do I then define tracker =0? Abd that way if they cycle back to monitoring of will be restarted?

• I like to use the modulus function for things like this:

pTesting = if(mod(_stage;12)=0;1;0)

When _stage is evenly divisible by 12, mod() yields a zero, otehrwise it gives the integer remainder i.e. mod(13;12) = 1

This avoids the need for a tracker update

• Your Modulo expression should be fine as long as you always want the test every 12 cycles. If the testing interval can change based on any event (like a positive test), then you would need something more complex.

Note that if you use a Logic node rather than a chance node then the probability expression changes to a simpler logic expression.

• Chance node branch probability: if(mod(_stage;12)=0;1;0)
• Logic node branch logic expression: mod(_stage;12)=0
• Yes, the modulo assumes testing every three years with 3-month cycle lengths. Could do something like mod(_stage; testing_frequency) if the testing interval changes?

• Thank you so much. This is very helpful. I am hoping to use this same formula in other places in this model, but it would be a bit more complicated as I would want the testing at an interval following a prior stage (ie ever 1 year after treatment, which does not occur at the beginning of the model)? Any advice on how to set the "start time" based on the beginning of entering a state (ie post-treatment) rather than the beginning of the model. Im guessing you use a tracker for time of when they move to that point in the model, but am not fully confident on how to do that.

• You can do just as you said, set a tracker equal to _stage when they enter the state then use an expression like _stage - tracker to determine how much time has passed since then. Then make the probability for testing based on the time since entering the state.

Please sign in to leave a comment.