'An id statement is required for multi-state models' error in multivariate cox regression analysis using R
1
0
Entering edit mode
2.1 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"))


R survival analysis • 6.2k views
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.

5
Entering edit mode
2.1 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.

1
Entering edit mode

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

2
Entering edit mode

0
Entering edit mode