I am new to using Markov Chains and have a problem that I haven't found a solution to. I am trying to fit a Markov Chain to a dataset to get the transition probabilities that people switch from one state to another, and I am wondering how I take the effect of individual participants into account when building the model.
Here's an example:
#Here's a dataframe with participant numbers and their state: A, B, C
DF <- data.frame(pp = rep(1:10, each = 3),
state = sample(rep(LETTERS[1:3], each = 10)))
> head(DF)
pp state
1 1 A
2 1 A
3 1 B
4 2 A
5 2 B
6 2 B
I can't just fit a Markov Chain to the state column as this would ignore the participant information, and it doesn't make sense to get the transition probability across two participants, for example:
mcFit <- markovchainFit(data=DF$state)
Do I need to fit a transition matrix to each participant individually and then average across them? And if so, how would I got about this?
Further, in this case, how would you deal with non-identical transition matrices across participants? E.g. some participants might not have any transitions between the states A and C, while others would:
#Example of Participant 1
A B
A 0.25 0.50
B 0.15 0.55
#Example of Participant 2
A C
A 0.50 0.25
C 0.25 0.50
Any help with this or recommendations of resources would be greatly appreciated.
markovchainFitwill interpret the vector as a sequence of short transitions. See the help for details. You can also pass it a list. That would give you global transition probs - a null model you can test the hypothesis that anyone is different (somehow...) - SpacedmanmarkovchainFit(c(1,2,1,NA,1,1,1,2))andmarkovchainFit(list(c(1,2,1),c(1,1,1,2)))- same outputs, but no loglik in the second case... - Spacedman