1
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ 1) Can you add some info about the form of the data set: panel_data? 2) Is the identical transition matrix for both covariates the same as the input matrix M? 3) Is there a reason for the choice of values 40000 and 1e6? $\endgroup$
    – Adam Kells
    Oct 15, 2021 at 16:28
  • 1
    $\begingroup$ I have learned that the cause of this problem is that I didn't transform sex (which is a character vector) to a factor. In this case, msm() will silently ignore this covariate, which is why the Q matrices were the same. I had tried to specify covariates = ~ factor(sex) but this didn't help. TL;DR: categorical variables should be coded as factors before using these as covariates with the msm() function. $\endgroup$
    – Stijn
    Oct 16, 2021 at 8:24

1 Answer 1

1
$\begingroup$

I have learned that the cause of this problem is that I didn't transform sex (which is a character vector) to a factor. In this case, msm() will silently ignore this covariate, which is why the Q matrices were the same. I had tried to specify covariates = ~ factor(sex) but this didn't help.

TL;DR: categorical variables should be coded as factors before using these as covariates with the msm() function.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.