代码如下,set.seed里面是学号,数据是随机生成的,但是运行的时候显示
Warning message:
In coxph.fit(X, Y, istrat, offset, init, control, weights = weights, :
Loglik converged before variable 1 ; coefficient may be infinite.
这是原代码:
library(survival)
RNGkind(sample.kind = "Rejection")
set.seed(9766) ## Change this number
#
# Generate sample A times with censorng
#
LenA <- 5
TimeA <- sort(round(rexp(LenA, 0.48), digits = 10))
CensorA <- rbinom(LenA,1,0.5)
if(sum(CensorA[1:(LenA-1)]) == 0){
CensorA[1] <- 1
}
cbind(TimeA, CensorA)
#
# Generate sample B times with censorng
#
LenB <- 5
TimeB <- sort(round(rexp(LenB, 0.52), digits = 10))
CensorB <- rbinom(LenB,1,0.4)
if(sum(CensorB[1:(LenB-1)]) == 0){
CensorB[1] <- 1
}
cbind(TimeB, CensorB)
#
# Combine data
#
Time <- c(TimeA, TimeB)
Censor <- c(CensorA, CensorB)
Group <- factor(c(rep(1,LenA), rep(2,LenB)))
#
LenCom <- LenA + LenB
Age <- floor(runif(LenCom,10,100))
#
cbind(Time, Censor, Group, Age)
## Fit a Cox proportional hazards model
Cox.fit <- coxph(Surv(Time, Censor) ~ Group + Age)
我输入过其他数字,9765和9767都没有这个问题,附近的数只有9762出现了同样的问题,所以问题是出在我这个学号上吗……?