'An id statement is required for multi-state models' error in multivariate cox regression analysis using R
1
0
Entering edit mode
3.6 years ago
1021jiyoung ▴ 10

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 • 9.2k views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY
5
Entering edit mode
3.6 years ago

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.

ADD COMMENT
1
Entering edit mode

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

ADD REPLY
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2339 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6