I am fitting a continuous-time Markov model to a panel dataset using the R package MSM
. Because I am interested in sex-differences in transition rates, I fit the model with covariate sex
("M" or "F") by running
model_object <- msm(
formula = state ~ nr_years,
subject = id_var,
qmatrix = M, # matrix encoding allowed transitions between states
data = panel_data,
covariates = ~ sex,
control = list(fnscale = 40000, maxit = 1e6) # got these from the help pages
)
After fitting the model I obtain the transition rate matrix using
qmatrix.msm(model_object, covariates = list(sex = "M"))
qmatrix.msm(model_object, covariates = list(sex = "F"))
These lines the exact same transition rate matrix. This is a bit unexpected to be, because when I use the hazard.msm
function to extract hazard ratios, there are some differences between sexes ( are even statistically significant).
Does this make sense statistically?
panel_data
? 2) Is the identical transition matrix for both covariates the same as the input matrixM
? 3) Is there a reason for the choice of values40000
and1e6
? $\endgroup$msm()
will silently ignore this covariate, which is why the Q matrices were the same. I had tried to specifycovariates = ~ factor(sex)
but this didn't help. TL;DR: categorical variables should be coded as factors before using these as covariates with themsm()
function. $\endgroup$