I´m trying to calculate the next state from a given probability vector extracted from a transition matrix.
probs <- structure(c(0.876896837675484, 0.101918293545303, 0.0189210190005101,
0.00220982524291829, 5.40245357842536e-05), .Names = c("State 1",
"State 2", "State 3", "State 4", "State 5"))
Where probs stands for the probability vector, the next step is to calculate the output given a binomial distribution.
set.seed(1)
rbinom(n = 5,size = 1,prob = probs)
Where n is number of observations (in this case state 1 --> State 5), size is number of trials (1 success or 0 failed) and prob is the probability of success of each observation and the function returns the following output:
1,0,0,0,0
So I'm assuming that the more probable ouput is the state 1 after one step, but sometimes I get the following:
1,0,1,0,0
But that wouldn't be possible because the person should only go to a certain state from his previous step.
Anyone has an idea on how to solve this?
Thanks for your time
Solved: I should have used rmultinom instead of rbinom