N = 3
L = 24
# time-varying mean dwell times
Lambda = exp(matrix(rnorm(L*N, 2, 0.5), nrow = L))
sizes = c(25, 25, 25) # approximating chain with 75 states
# state dwell-time distributions
dm = list()
for(i in 1:3){
dmi = matrix(nrow = L, ncol = sizes[i])
for(t in 1:L){
dmi[t,] = dpois(1:sizes[i]-1, Lambda[t,i])
}
dm[[i]] = dmi
}
## homogeneous conditional transition probabilites
# diagonal elements are zero, rowsums are one
omega = matrix(c(0,0.5,0.5,0.2,0,0.8,0.7,0.3,0), nrow = N, byrow = TRUE)
# calculating extended-state-space t.p.m.s
Gamma = tpm_phsmm(omega, dm)
## inhomogeneous conditional transition probabilites
# omega can be an array
omega = array(rep(omega,L), dim = c(N,N,L))
omega[1,,4] = c(0, 0.2, 0.8) # small change for inhomogeneity
# calculating extended-state-space t.p.m.s
Gamma = tpm_phsmm(omega, dm)
Run the code above in your browser using DataLab