4

早上好,

在匹配案例/对照研究后,我一直在尝试在 R 中进行分层逻辑回归,但在我看来遇到了一个意想不到的错误。我已经使用 mtcars 数据集重现了该错误:

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)

coxph(formula = Surv(rep(1, 32L), am) ~ vs + strata(cyl), data = test, 中的错误:Cox 模型不支持“mright”生存数据

在我的理解中,clogit-function 创建了时间参数,R 似乎对此有问题。当我不使用 am 作为一个因素时,错误就消失了,但这就是整体,但我不必将其标记为一个因素才能进行逻辑回归吗?

顺便说一句,我使用的是 R 3.2.2 和生存包 2.41-3,但是由于这两个函数似乎都来自生存包,所以这不应该是问题的根源,对吧?或者这个错误在较新的 R 版本下无法重现?

4

1 回答 1

0

我认为@MarcoSandri 或Member0815 应该输入说明此解决方案的代码,以便可以将问题视为“已回答”。

> 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. 
于 2021-09-19T20:08:46.697 回答