Given the previous state and a random number `u_rand`, this function returns the next state in a 3-state first-order Markov chain. The transition probabilities are state- and index-specific.
Arguments
- state_prev
Integer. The current (previous) state (0, 1, or 2).
- u_rand
Numeric. A random number in [0, 1] used to sample the next state.
- idx
Integer. Index for selecting transition probabilities (e.g., time step or spatial location).
- p00
Numeric vector. Probability of transition from state 0 to 0.
- p01
Numeric vector. Probability of transition from state 0 to 1.
- p10
Numeric vector. Probability of transition from state 1 to 0.
- p11
Numeric vector. Probability of transition from state 1 to 1.
- p20
Numeric vector. Probability of transition from state 2 to 0.
- p21
Numeric vector. Probability of transition from state 2 to 1.