I have the state - transition data with multiple sequences of unequal lengths, each sequence corresponding to one subject/person:
head(prob_tbl2)
period1 period2 period3 period4 period5 period6 period7 period8
1 <NA> active active active active active active active
2 active active active active active active active active
3 active active active active active active active active
4 <NA> <NA> active lapsed1 active lapsed1 active lapsed1
5 <NA> <NA> active lapsed1 lapsed2 lapsed3 lapsed4 lapsed5
6 <NA> active lapsed1 lapsed2 lapsed3 lapsed4 lapsed5 lapsed6
Based on this data, I created a probability matrix (as suggested here):
trans.matrix <- function(X, prob=T)
{
tt <- table( c(X[,-ncol(X)]), c(X[,-1]) )
if(prob) tt <- tt / rowSums(tt)
tt
}
prob_table= trans.matrix(as.matrix(prob_tbl2))
prob_table
active lapsed1 lapsed2 lapsed3 lapsed4 lapsed5 lapsed6 lapsed7
active 0.56006735 0.43993265 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
lapsed1 0.19183552 0.00000000 0.80816448 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
lapsed2 0.10206773 0.00000000 0.00000000 0.89793227 0.00000000 0.00000000 0.00000000 0.00000000
lapsed3 0.06437215 0.00000000 0.00000000 0.00000000 0.93562785 0.00000000 0.00000000 0.00000000
lapsed4 0.04468764 0.00000000 0.00000000 0.00000000 0.00000000 0.95531236 0.00000000 0.00000000
lapsed5 0.04115773 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.95884227 0.00000000
lapsed6 0.02306733 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.97693267
What is the way I could validate those probabilities, e.g. receive stadard errors/confidence intervals and cross-validate them against a new/unseen dataset? Could I bootstrap my data or apply MLE to get the uncertainty levels, if so, how to do it in R?
I tried to use library(markovchain)
, with no much luck with my dataset, I described the problem here
Clearly, I'm new to Markov chains so any hints will be helpful!
library(markovchain)
but it seems to work only for the sequence data (see the details here ) $\endgroup$