user2968765
user2968765

Reputation: 155

r/ msm-package/ how to fit and get discrete time, time-homogenous transition probabilities?

I have a sequence of states and corresponding months.

mcdata <- structure(list(state = structure(c(2L, 1L, 2L, 2L, 2L, 2L, 4L, 
4L, 2L, 4L, 2L, 3L, 1L, 3L, 2L, 2L, 2L, 4L, 2L, 3L, 4L, 2L, 3L, 
3L, 3L, 3L, 3L, 1L, 4L, 2L, 3L, 2L, 2L, 4L, 3L, 2L, 4L, 3L, 2L, 
2L, 3L), .Label = c("1", "2", "3", "4"), class = "factor"), month = c(1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
36, 37, 38, 39, 40, 41)), .Names = c("state", "month"), class = "data.frame",    
row.names = c(NA,-41L))

The transitions happen at exact and discrete times. The process can move to any state at any (discrete) time. I work with the assumption that the transition probabilities are time-independent.

I am interested in getting one step transition probabilities for the situation above with msm-package, which is designed for continuous time but has several attractive features I want to use later.

All transitions allowed:

transitions_allowed <- matrix(c( 
    1,1,1,1,
    1,1,1,1, 
    1,1,1,1,
    1,1,1,1), nrow=4, ncol=4, 
    byrow=TRUE, 
    dimnames=list(from=1:4,to=1:4)) 

to get the crude initial values and the transition probabilities with exact times:

library(msm)
crudein <-crudeinits.msm(state ~ month, data=mcdata, qmatrix=transitions_allowed)
mod <- msm(state ~ month, data = mcdata, qmatrix = crudein, exacttimes=TRUE)
pmatrix.msm(mod,t=1)

I believe resulting pmatrix.msm transition probabities are not correct for my situation (e.g. in sequence state "1" is not immediately followed by state "1"): discrete exact time and transition probabilities time-homogenous.

I have defined exacttimes=TRUE and can see that the formula still includes month as explaining variable. Replacing 'state ~ month' with 'state ~." does not help.

Initial values can also be problematic. Changing them to transition probabilities computed with 'markovchain' did not change the situation.

Is there something I can do to solve this using msm-package? Thanks.

Upvotes: 0

Views: 1451

Answers (1)

Chris Jackson
Chris Jackson

Reputation: 871

In msm, you have to assume that there is some continuous-time Markov process underlying the data, so all models have to be parameterised by a transition intensity matrix, even if you're just interested in the transition probabilities. I don't think there is any continuous-time Markov model in which there is zero probability of remaining in the same state in one time unit later, since the staying time in each state has an exponential distribution.

Upvotes: 1

Related Questions