I am trying to calculate confidence intervals for transition probabilities between a set of discrete states over time (involving multiple time steps).
Here is a toy example to get the transition probabilities:
# create a toy dataset states<- c("A","B","C") t1 <- sample(states,30,c(2/3,1/6,1/6),replace=T) t2 <- sample(states,30,c(2/3,1/6,1/6),replace=T) t3 <- sample(states,30,c(2/3,1/6,1/6),replace=T) df.t <- data.frame(t1=t1,t2=t2,t3=t3) transition.matrix.t1 <- table(t1,t2) transition.matrix.t2 <- table(t2,t3) prob.trans.t1 <- t(apply(transition.matrix.t1,1,function(x) x/sum(x))) prob.trans.t2 <- t(apply(transition.matrix.t2,1,function(x) x/sum(x)))
Each row of df.t is a sample observation over 3 time periods. prob.trans.t1 contains the transition probabilities for the time step t1->t2.
In reality, I don't have any previous knowledge about the underlying probabilities and I only have a randomly picked sample. I would like to calculate a 95% confidence interval for the above transition probabilities transition.matrix.t1, transition.matrix.t2.