'What is the solution to Error during conditional logistic regression in R?

set<-c(1,1,1,2,2,2)  
gender<-c(1,0,1,0,1,0)  
smoke<-c(1,1,0,0, 1,0)  
case_control<-c(1,0,0,1,0,0)

data<-data.frame(set, gender, smoke, case_control)  
data$gender<-factor(data$gender, levels=c(0,1), labels=c("female", "male"))  
data$smoke<-factor(data$smoke, levels=c(0,1), labels=c("no", "yes"))  
data$case_control<-factor(data$case_control, levels=c(0,1), labels=c("control", "case"))

In dataset named "data", I tried to do conditional logistic regression

library(survival)  
clogit(formula = data$case_control~data$gender+strata(data$set), data = data, method = "exact")**

Error was displayed as below.

Error in coxph(formula = Surv(rep(1, 6L), data$case_control) ~ data$gender + : an id statement is required for multi-state models

What could be the possible solution to this problem?



Solution 1:[1]

I've run into this too. clogit uses coxph and surv under the hood and after looking at the documentation for surv it appears that the problem is that the event argument (case_control in this example) is a factor. When the event is a factor, surv assumes there are multiple endpoints (the multi-state models mentioned in the error), so it needs an id label for each row to know which outcomes to assign to which participants. If you change your outcome to a numeric variable with

clogit(formula = as.numeric(data$case_control) ~
data$gender+strata(data$set), data = data, method = "exact")

it works just fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pgcudahy