This is a test version of Biostars. For the public version, visit https://www.biostars.org.
'An id statement is required for multi-state models' error in multivariate cox regression analysis using R

Hey guys, I am stuck here with this error message while running survival analysis in R:

> hcm.cox <- coxph(Surv(FU, MACE) ~ Fibrosis + MaxLVWT, data = hcm)
Error in coxph(Surv(FU, MACE) ~ Fibrosis + MaxLVWT, data = hcm) : 
  an id statement is required for multi-state models

FU stands for follow-up period (numeric) and MACE stands for events (factor; 1 = no, 2 = yes). Fibrosis is a binary factor (1 = -, 2 = +) and maxLVWT is a continuous numeric variable.

Before running the analysis, I've converted MACE and Fibrosis into binary factors by doing so:

> hcm$MACE <- factor(hcm$MACE, levels = c("N", "Y"), labels = c("1", "2"))
> hcm$Fibrosis <- factor(hcm$Fibrosis, levels = c("-", "+"), labels = c("1", "2"))

I can't understand why the error keeps popping up, please help me out!

r survival analysis

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

1 answer

You are not providing minimum data to reproduce the scenario. But if you convert theevent variable, MACE into a numeric vector it should work. you can do this by doing so:

hcm$MACE <- as.numeric(hcm$MACE)

The error an id statement is required for multi-state models is related to having more than two categories in the event variable. This finely discussed here. Although in your case, you are not dealing with a multi-state model, it's going to complain about missing ids! This is a bit wired to me.

Thank you for posting this! I've changed MACE into a numerical variable and it works :)

Cool, if this resolved your issue, please upvote (like) the answer

Thanks. I had same issue here and your suggestion works. Upvoted.

Log in to answer this question.