0

使用的库是:library(survival) library(splines) library(boot) library(frailtypack),使用的函数在 library frailty pack 中。
在我的数据中,我有两个经常性事件(delta.stable 和 delta.unstable)和一个终端事件(delta.censor)。有一些随时间变化的解释变量,例如失业率(u.rate)(每季度一次),这就是我的数据集按季度划分的原因。这里有一个指向下面代码中使用的子示例的链接,以防万一看到错误可能会有所帮助。 https://www.dropbox.com/s/spfywobydr94bml/cr_05_males_services.rda 问题是在出现警告消息之前运行需要很长时间。

Survival 函数的主要变量是: 我有两个经常发生的事件: delta.unstable (unst.):当个人找到一份不稳定的工作时取值一。delta.stable(稳定):当个人找到稳定的工作时取值一。还有一个终结事件 delta.censor (d.censor):当个人死亡、退休或移民时取值 1。

row     id contadorbis unst. stable d.censor    .t0 .t
1   78  1   0   1   0   0   88
2   101 2   0   1   0   0   46
3   155 3   0   1   0   0   27
4   170 4   0   0   0   0   61
5   170 4   1   0   0   61  86
6   213 5   0   0   0   0   92
7   213 5   0   0   0   92  182
8   213 5   0   0   0   182 273
9   213 5   0   0   0   273 365
10  213 5   1   0   0   365 394
11  334 6   0   1   0   0   6
12  334 7   1   0   0   0   38
13  369 8   0   0   0   0   27
14  369 8   0   0   0   27  119
15  369 8   0   0   0   119 209
16  369 8   0   0   0   209 300
17  369 8   0   0   0   300 392

当我申请时,multivePenal我收到以下消息:

Error en aggregate.data.frame(as.data.frame(x), ...) : 
arguments must have same length
Además: Mensajes de aviso perdidos

In Surv(.t0, .t, delta.stable) : Stop time must be > start time, NA created
#### multivePenal function
fit.joint.05_malesP<multivePenal(Surv(.t0,.t,delta.stable)~cluster(contadorbis)+terminal(as.factor(delta.censor))+event2(delta.unstable),formula.terminalEvent=~1, formula2=~as.factor(h.skill),data=cr_05_males_serv,Frailty=TRUE,recurrentAG=TRUE,cross.validation=F,n.knots=c(7,7,7), kappa=c(1,1,1), maxit=1000, hazard="Splines")

我检查了 if Surv(.t0,.t,delta.stable)contains NA,并且没有NA's。

此外,当我frailtyPenal为两种可能的组合申请相同的数据时,该函数运行良好并且我得到了结果。我花了一个星期看这个,我没有找到关键。我希望能对这个问题有所了解。

#delta unstable+death

enter code here

fit.joint.05_males<-frailtyPenal(Surv(.t0,.t,delta.unstable)~cluster(id)+u.rate+as.factor(h.skill)+as.factor(m.skill)+as.factor(non.manual)+as.factor(municipio)+as.factor(spanish.speakers)+ as.factor(no.spanish.speaker)+as.factor(Aged.16.19)+as.factor(Aged.20.24)+as.factor(Aged.25.29)+as.factor(Aged.30.34)+as.factor(Aged.35.39)+ as.factor(Aged.40.44)+as.factor(Aged.45.51)+as.factor(older61)+ as.factor(responsabilities)+
terminal(delta.censor),formula.terminalEvent=~u.rate+as.factor(h.skill)+as.factor(m.skill)+as.factor(municipio)+as.factor(spanish.speakers)+as.factor(no.spanish.speaker)+as.factor(Aged.16.19)+as.factor(Aged.20.24)+as.factor(Aged.25.29)+as.factor(Aged.30.34)+as.factor(Aged.35.39)+as.factor(Aged.40.44)+as.factor(Aged.45.51)+as.factor(older61)+ as.factor(responsabilities),data=cr_05_males_services,n.knots=12,kappa1=1000,kappa2=1000,maxit=1000, Frailty=TRUE,joint=TRUE, recurrentAG=TRUE)

###Be patient. The program is computing ... 
###The program took 2259.42 seconds 

#delta stable+death
fit.joint.05_males<frailtyPenal(Surv(.t0,.t,delta.stable)~cluster(id)+u.rate+as.factor(h.skill)+as.factor(m.skill)+as.factor(non.manual)+as.factor(municipio)+as.factor(spanish.speakers)+as.factor(no.spanish.speaker)+as.factor(Aged.16.19)+as.factor(Aged.20.24)+as.factor(Aged.25.29)+as.factor(Aged.30.34)+as.factor(Aged.35.39)+as.factor(Aged.40.44)+as.factor(Aged.45.51)+as.factor(older61)+as.factor(responsabilities)+terminal(delta.censor),formula.terminalEvent=~u.rate+as.factor(h.skill)+as.factor(m.skill)+as.factor(municipio)+as.factor(spanish.speakers)+as.factor(no.spanish.speaker)+as.factor(Aged.16.19)+as.factor(Aged.20.24)+as.factor(Aged.25.29)+as.factor(Aged.30.34)+as.factor(Aged.35.39)+as.factor(Aged.40.44)+as.factor(Aged.45.51)+as.factor(older61)+as.factor(responsabilities),data=cr_05_males_services,n.knots=12,kappa1=1000,kappa2=1000,maxit=1000, Frailty=TRUE,joint=TRUE, recurrentAG=TRUE)
###The program took 3167.15 seconds
4

3 回答 3

1

因为您既没有提供有关使用的包的信息,也没有提供运行multivepenalfrailtyPenal所需的数据,所以我只能帮助您完成Surv部分(因为我碰巧加载了该包)。

您提供的Surv警告消息 ( In Surv(.t0, .t, delta.stable) : Stop time must be > start time, NA created) 表明您的变量.t0( 中的time参数Surv,在警告中称为“开始时间”)和/或.ttime2参数,警告中的“停止时间”)有些奇怪。我用一个简单的例子检查这种可能性

# read the data you feed `Surv` with
df <- read.table(text = "row     id contadorbis unst. stable d.censor    .t0 .t
1   78  1   0   1   0   0   88
2   101 2   0   1   0   0   46
3   155 3   0   1   0   0   27
4   170 4   0   0   0   0   61
5   170 4   1   0   0   61  86
6   213 5   0   0   0   0   92
7   213 5   0   0   0   92  182
8   213 5   0   0   0   182 273
9   213 5   0   0   0   273 365
10  213 5   1   0   0   365 394
11  334 6   0   1   0   0   6
12  334 7   1   0   0   0   38
13  369 8   0   0   0   0   27
14  369 8   0   0   0   27  119
15  369 8   0   0   0   119 209
16  369 8   0   0   0   209 300
17  369 8   0   0   0   300 392", header = TRUE)

# create survival object
mysurv <- with(df, Surv(time = .t0, time2 = .t, event = stable))
mysurv

# create a new data set where one .t for some reason is less than .to
# on row five .t0 is 61, so I set .t to 60
df2 <- df
df2$.t[df2$.t == 86] <- 60

# create survival object using new data which contains at least one Stop time that is less than Start time
mysurv2 <- with(df2, Surv(time = .t0, time2 = .t, event = stable))

# Warning message:
#  In Surv(time = .t0, time2 = .t, event = stable) :
#  Stop time must be > start time, NA created
# i.e. the same warning message as you got

# check the survival object
mysurv2

# as you can see, the fifth interval contains NA
# I would recommend you check .t0 and .t in your data set carefully 
# one way to examine rows where Stop time (.t) is less than start time (.t0) is:
df2[which(df2$.t0 > df2$.t), ]

我不熟悉,multivepenal但似乎它不接受包含 NA 间隔的生存对象,而frailtyPenal可能会这样做。

于 2013-09-08T11:36:20.743 回答
0

包的作者告诉我这个功能还没有完成,所以也许这就是它不能正常工作的原因。

于 2013-09-10T10:22:33.643 回答
0

我遇到了同样的错误并得出了这个解决方案。

frailtyPenal()不接受data.frames不同长度的。data.frameused inSurvdata.framenamed in data=in的frailtyPenal长度必须相同。我使用 Cox 回归来识别不完整的案例,重置生存对象以排除丢失的案例,最后运行frailtyPenal

library(survival)
library(frailtypack)

data(readmission)

#Reproduce the error

#change the first start time to NA
  readmission[1,3] <- NA 

#create a survival object with one missing time
  surv.obj1 <- with(readmission, Surv(t.start, t.stop, event))

#observe the error
  frailtyPenal(surv.obj1 ~ cluster(id) + dukes, 
               data=readmission, 
               cross.validation=FALSE,
               n.knots=10,
               kappa=1,
               hazard="Splines")

#repair by resetting the surv object to omit the missing value(s)

#identify NAs using a Cox model
  cox.na <- coxph(surv.obj1 ~ dukes, data = readmission)

#remove the NA cases from the original set to create complete cases
  readmission2 <- readmission[-cox.na$na.action,]

#reset the survival object using the complete cases
  surv.obj2 <- with(readmission2, Surv(t.start, t.stop, event))

#run frailtyPenal using the complete cases dataset and the complete cases Surv object
  frailtyPenal(surv.obj2 ~ cluster(id) + dukes,
               data = readmission2, 
               cross.validation = FALSE,
               n.knots = 10,
               kappa = 1,
               hazard = "Splines")
于 2020-01-23T01:52:46.407 回答