4

Good morning,

I have been trying to do a stratified logistic regression in R after matching for a Case/Control study and encountered a in my opinion unexpected mistake. I have reproduced the error using the mtcars data set:

test=mtcars
test$am=as.factor(test$am)
test$cyl=as.factor(test$cyl)
test$vs=as.factor(test$vs)
library(survival)
clogit(am~vs+strata(cyl),data=test)

Error in coxph(formula = Surv(rep(1, 32L), am) ~ vs + strata(cyl), data = test, : Cox model doesn't support "mright" survival data

In my understanding the clogit-function creates the time parameter, which R seemingly has a problem with. The mistake disappears, when I don't use a am as a factor, but that is the whole, but don't I have to label it as a factor in order to do a logistic regression?

By the way, I am using R 3.2.2 and survival package 2.41-3, but since it seems both functions involved are from the survival package, this shouldn't be the root of the problem here, right? Or is this mistake not reproducable under a newer R-Version?

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
Member0815
  • 51
  • 1
  • 3
  • 2
    At the end of the help page given by `?clogit` you can find an example of the use of this command. The outcome is not defined as a factor, but is logical/numerical. Hence, I suggest to define `am` as 0/1 or FALSE/TRUE. – Marco Sandri Sep 08 '17 at 09:08
  • 2
    Thank you, with the response coded as logical, it works, I should have caught that :) – Member0815 Sep 08 '17 at 10:34

1 Answers1

0

I think either @MarcoSandri or Member0815 should have put in code that illustrated this solution so that the question could be seen as "answered".

> test=mtcars
> test$am=as.logical(test$am)
> test$cyl=as.factor(test$cyl)
> test$vs=as.factor(test$vs)
> library(survival)
> clogit(am~vs+strata(cyl),data=test)
Call:
clogit(am ~ vs + strata(cyl), data = test)

          coef  exp(coef)   se(coef)      z     p
vs1 -2.248e+01  1.733e-10  2.159e+04 -0.001 0.999

Likelihood ratio test=7.75  on 1 df, p=0.005378
n= 32, number of events= 13 
Warning message:
In coxexact.fit(X, Y, istrat, offset, init, control, weights = weights,  :
  Loglik converged before variable  1 ; beta may be infinite. 
IRTFM
  • 258,963
  • 21
  • 364
  • 487