I have following two-state Markov chain:
pre<-cbind(c(rep("rain",100),rep("sun",100),rep("rain",100)))
post<-cbind(c(rep("rain",50),rep("sun",70),rep("rain",100),rep("sun",80)))
df<-cbind(pre,post)
df<-as.data.frame(df)
colnames(df)<-c("pre","post")
states<-c("rain","sun")
probsCase<-function(i,j){
sum(as.character(df$pre)==states[i] & as.character(df$post)==states[j])/sum(as.character(df$pre)==states[i])
}
transitionMatrix<-outer(1:2,1:2,Vectorize(probsCase))
colnames(transitionMatrix)<-states
rownames(transitionMatrix)<-states
library(diagram)
plotmat(transitionMatrix,relsize=0.75)
Which produces the following plot:
It seems to me that the arrows between "sun" and "rain" should be pointing the opposite directions, otherwise the respective proportions will not add up to 1.
For comparison, you can look at this similar plot online where the proportions from do add up to 1
Any thoughts?