# 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

Belinda OrmeYou 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.

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

David NaimarkI 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

Andrew MunzerYour 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.

David NaimarkYes, 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?

Jonathan ErlichThank 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.

Andrew MunzerYou 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.

Nafsika AfentouHello,

I am trying to apply the if+mod function to a markov model as Andrew and David suggested above but it doesn't work. My chance node has three transition probabilities (i.e. prob1, prob2, prob3 and prob4) and I want a probability to be applied every 6 cycles only. So I've kept prob1=# and then replaced the remaining probabilities as follows:

prob2=if(mod(_stage;6)=0;x;0)

prob3=if(mod(_stage;6)=0;y;0)

prob4=if(mod(_stage;6)=0;z;0)

However in the Markov summary report it seems that while the %cohort in prob2 and prob4 only change every 6 cycles, prob3 and prob1 keep changing every cycle. Does anyone know how to fix this?

Thank you

Belinda OrmeNafsika

Based on the information you have provided above, the probabilities 2 - 4 should be using x, y and z only when _stage is a multiple of 6. So it is strange they are not all following the same pattern.

It is hard to diagnose the issue without seeing the actual implementation in the model. To provide further assistance, we would probably need to look at your model which you can send to support@treeage.com.

Andrew MunzerThis question has been moved to a support ticket as the issue is specific to this model.

Please sign in to leave a comment.