JM 的 jointModel 抛出不清楚的错误信息
jointModel from JM throws unclear error message
我正在尝试使用 R 包 "JM" 将纵向时间与事件数据相匹配。这是我第一次尝试联合模型并遵循教科书方法:
aids.id <- aids[!duplicated(aids$patient),]
lmeFit.aids <- lme(CD4~obstime + obstime:drug, random=~obstime|patient, data=aids)
coxFit.aids <- coxph(Sdurv(Time,death)~drug,data=aids.id, x=TRUE)
jointFit.aids <- jointModel(lmeFit.aids, coxFit.aids, timeVar="obstime",method="piecewise-PH-aGH")
summary(jointFit.aids)
代码按预期运行。但是当我使用自己的数据时,它就不起作用了。
海峡(数据)
'data.frame':6436 观测值。 13 个变量:
$ patnr : 因子 w/ 1669 水平 "0010000158","0010000278",..: 4 4 4 4 7 7 7 7 7 7 ...
$ sex : 因子 w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
$ 日期:POSIXct,格式:“2008-08-08”“2010-01-25”“2012-02-24”“2012-04-21”...
$ 时间:num 1355 1355 1355 1355 834 ...
$ Crea:数量 7.4 9.6 12.3 10.3 0.8 ...
$ CysC:数量 6.2 5.84 6.17 5.32 0.9 0.94 0.92 0.91 0.91 0.91 ...
$ 死亡日期:POSIXct,格式:"2012-04-24" "2012-04-24" "2012-04-24" "2012-04-24" ...
$ start_date: POSIXct, 格式: "2008-08-08" "2008-08-08" "2008-08-08" "2008-08-08" ...
$ stop_date : POSIXct, 格式: "2010-01-25" "2012-02-24" "2012-04-21" "2012-04-24" ...
$ 开始:num 0 535 1295 1352 0 ...
$ 停止:num 535 1295 1352 1355 3 ...
$ obstime : num 0 535 1295 1352 0 ...
$ 事件:num 0 0 0 1 0 0 0 0 0 0 ...
这些是数据框的前 20 行:
patnr sex date time Crea CysC deathdate start_date stop_date start stop obstime event
637 0010000343 1 2008-08-08 1355.00000 7.40 6.20 2012-04-24 2008-08-08 2010-01-25 0.00000 535.04167 0.00000 0
816 0010000343 1 2010-01-25 1355.00000 9.60 5.84 2012-04-24 2008-08-08 2012-02-24 535.04167 1295.04167 535.04167 0
1171 0010000343 1 2012-02-24 1355.00000 12.31 6.17 2012-04-24 2008-08-08 2012-04-21 1295.04167 1352.00000 1295.04167 0
1201 0010000343 1 2012-04-21 1355.00000 10.35 5.32 2012-04-24 2008-08-08 2012-04-24 1352.00000 1355.00000 1352.00000 1
1363 0010000873 1 2011-12-05 834.00000 0.80 0.90 <NA> 2011-12-05 2011-12-08 0.00000 3.00000 0.00000 0
1370 0010000873 1 2011-12-08 834.00000 0.52 0.94 <NA> 2011-12-05 2011-12-09 3.00000 4.00000 3.00000 0
1372 0010000873 1 2011-12-09 834.00000 0.45 0.92 <NA> 2011-12-05 2011-12-18 4.00000 13.00000 4.00000 0
1386 0010000873 1 2011-12-18 834.00000 0.34 0.91 <NA> 2011-12-05 2011-12-19 13.00000 14.00000 13.00000 0
1387 0010000873 1 2011-12-19 834.00000 0.31 0.91 <NA> 2011-12-05 2011-12-20 14.00000 15.00000 14.00000 0
1391 0010000873 1 2011-12-20 834.00000 0.62 0.91 <NA> 2011-12-05 2011-12-27 15.00000 22.00000 15.00000 0
1411 0010000873 1 2011-12-27 834.00000 0.61 1.44 <NA> 2011-12-05 2011-12-31 22.00000 26.00000 22.00000 0
1418 0010000873 1 2011-12-31 834.00000 0.43 1.18 <NA> 2011-12-05 2012-01-01 26.00000 27.00000 26.00000 0
1419 0010000873 1 2012-01-01 834.00000 0.46 1.22 <NA> 2011-12-05 2013-07-09 27.00000 581.95833 27.00000 0
1466 0010000873 1 2013-07-09 834.00000 0.85 0.91 <NA> 2011-12-05 2014-03-18 581.95833 834.00000 581.95833 0
1478 0010000873 1 2014-03-18 834.00000 1.20 1.00 <NA> 2011-12-05 2015-09-18 834.00000 1382.95833 834.00000 0
2020 0010002412 1 2015-03-26 23.95833 1.16 0.85 <NA> 2015-03-26 2015-04-10 0.00000 14.95833 0.00000 0
2035 0010002412 1 2015-04-10 23.95833 0.67 0.74 <NA> 2015-03-26 2015-04-14 14.95833 18.95833 14.95833 0
2043 0010002412 1 2015-04-14 23.95833 0.56 0.75 <NA> 2015-03-26 2015-04-16 18.95833 20.95833 18.95833 0
2046 0010002412 1 2015-04-16 23.95833 0.45 0.75 <NA> 2015-03-26 2015-04-17 20.95833 21.95833 20.95833 0
2049 0010002412 1 2015-04-17 23.95833 0.52 0.86 <NA> 2015-03-26 2015-04-18 21.95833 22.95833 21.95833 0
这是我使用的代码:
copd.id <- DATA[!duplicated(DATA$patnr),]
copd.id$event <- as.numeric(!is.na(copd.id$deathdate))
lmeFit.copd <- lme(CysC~obstime+obstime:sex, random=~obstime|patnr, data=DATA)
coxFit.copd <- coxph(Surv(time,event)~sex, data=copd.id, x=TRUE)
jointFit.copd <- jointModel(lmeFit.copd, coxFit.copd, timeVar="obstime",method="piecewise-PH-aGH")
summary(jointFit.copd)
我收到以下错误消息:
jointFit.copd <- jointModel(lmeFit.copd, coxFit.copd, timeVar="obstime",method="piecewise-PH-aGH") Fehler in
jointModel(lmeFit.copd, coxFit.copd, timeVar = "obstime", method =
"piecewise-PH-aGH") : it seems that there are longitudinal
measurements taken after the event times for some subjects (i.e.,
check subject(s): 0010000343, 0010000695, 0010000873, 0010002412,
0010002782, 0010003305, 0010003865, 0010003975, 0010004179,
0010004534, 0010004943, 0010005724, 0010007075, 0010007495,
0010008083, 0010008279, 0010008488, 0010008692, 0010008751,
0010009439, 0010010330, 0010011663, 0010012262, 0010012543,
0010012575, 0010013477, 0010014195, 0010015876, 0010016684,
0010017677, 0010018443, 0010019213, 0010019403, 0010019646,
0010020446, 0010020695, 0010021115, 0010021159, 0010021916,
0010022698, 0010024937, 0010026652, 0010030656, 0010031115,
0010031654, 0010031760, 0010033685, 0010034046, 0010034303,
0010035140, 0010037655, 0010038043, 0010038117, 0010038168,
0010038622, 0010039907, 0010042346, 0010044178, 0010046528,
0010046756, 0010048385, 0010049308, 0010049625, 0010049854,
0010050309, 0010051869, 0010052193, 0010052645, 0010052927,
0010053024, 0010054182, 0010055882, 001
summary(jointFit.copd) Fehler in summary(jointFit.copd) : Objekt 'jointFit.copd' nicht gefunden
问题是:我检查了数据,事件发生后没有测量值。
我在这里错过了什么?
尝试在 运行 模型之前对 patnr
进行排序 DATA
。我可以通过制作一个未排序的 newid
来引发您在 aids
示例中为 DATA
得到的错误。
library(JM)
is.unsorted(aids$patient)
length(unique(aids$patient))
## make newid that is unsorted
no.rows <- rle(c(aids$patient))
aids$newid <- paste0(rep( rep(LETTERS, length.out=467), no.rows$lengths), aids$patient)
is.unsorted(aids$newid)
length(unique(aids$newid))
## change `patient` to newid in the following lines to get
## error message for `jointFit.aids`
aids.id <- aids[!duplicated(aids$patient),]
lmeFit.aids <- lme(CD4~obstime + obstime:drug, random=~obstime|newid, data=aids)
coxFit.aids <- coxph(Surv(Time,death)~drug,data=aids.id, x=TRUE)
jointFit.aids <- jointModel(lmeFit.aids, coxFit.aids, timeVar="obstime",method="piecewise-PH-aGH")
summary(jointFit.aids)
当我看到 code for JM on github 时,我想到了这个。由于错误消息打印在 jointModel.R 中的第 139 行,我查看了该行上方的内容是如何定义的,并得出结论,假设数据集是根据 id 变量排序的。因此,虽然 DATA
中没有任何主题违反条件,但顺序在代码中被打乱了。在没有可重现示例的情况下,我的第一个提示是问题中给出的数据集的前 20 行的 ID 为 0010000343、0010000873、0010002412,但发布的错误消息列出了按排序顺序排列的 ID 为 0010000343,0010000695, 0010000873, 0010002412 -- 表示 DATA
未按 lme()
模型中列出的 id 变量 (patnr
) 排序。原始 aids
示例按 id (patient
).
排序
我正在尝试使用 R 包 "JM" 将纵向时间与事件数据相匹配。这是我第一次尝试联合模型并遵循教科书方法:
aids.id <- aids[!duplicated(aids$patient),]
lmeFit.aids <- lme(CD4~obstime + obstime:drug, random=~obstime|patient, data=aids)
coxFit.aids <- coxph(Sdurv(Time,death)~drug,data=aids.id, x=TRUE)
jointFit.aids <- jointModel(lmeFit.aids, coxFit.aids, timeVar="obstime",method="piecewise-PH-aGH")
summary(jointFit.aids)
代码按预期运行。但是当我使用自己的数据时,它就不起作用了。
海峡(数据) 'data.frame':6436 观测值。 13 个变量: $ patnr : 因子 w/ 1669 水平 "0010000158","0010000278",..: 4 4 4 4 7 7 7 7 7 7 ...
$ sex : 因子 w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
$ 日期:POSIXct,格式:“2008-08-08”“2010-01-25”“2012-02-24”“2012-04-21”...
$ 时间:num 1355 1355 1355 1355 834 ...
$ Crea:数量 7.4 9.6 12.3 10.3 0.8 ...
$ CysC:数量 6.2 5.84 6.17 5.32 0.9 0.94 0.92 0.91 0.91 0.91 ...
$ 死亡日期:POSIXct,格式:"2012-04-24" "2012-04-24" "2012-04-24" "2012-04-24" ...
$ start_date: POSIXct, 格式: "2008-08-08" "2008-08-08" "2008-08-08" "2008-08-08" ...
$ stop_date : POSIXct, 格式: "2010-01-25" "2012-02-24" "2012-04-21" "2012-04-24" ...
$ 开始:num 0 535 1295 1352 0 ...
$ 停止:num 535 1295 1352 1355 3 ...
$ obstime : num 0 535 1295 1352 0 ...
$ 事件:num 0 0 0 1 0 0 0 0 0 0 ...
这些是数据框的前 20 行:
patnr sex date time Crea CysC deathdate start_date stop_date start stop obstime event
637 0010000343 1 2008-08-08 1355.00000 7.40 6.20 2012-04-24 2008-08-08 2010-01-25 0.00000 535.04167 0.00000 0
816 0010000343 1 2010-01-25 1355.00000 9.60 5.84 2012-04-24 2008-08-08 2012-02-24 535.04167 1295.04167 535.04167 0
1171 0010000343 1 2012-02-24 1355.00000 12.31 6.17 2012-04-24 2008-08-08 2012-04-21 1295.04167 1352.00000 1295.04167 0
1201 0010000343 1 2012-04-21 1355.00000 10.35 5.32 2012-04-24 2008-08-08 2012-04-24 1352.00000 1355.00000 1352.00000 1
1363 0010000873 1 2011-12-05 834.00000 0.80 0.90 <NA> 2011-12-05 2011-12-08 0.00000 3.00000 0.00000 0
1370 0010000873 1 2011-12-08 834.00000 0.52 0.94 <NA> 2011-12-05 2011-12-09 3.00000 4.00000 3.00000 0
1372 0010000873 1 2011-12-09 834.00000 0.45 0.92 <NA> 2011-12-05 2011-12-18 4.00000 13.00000 4.00000 0
1386 0010000873 1 2011-12-18 834.00000 0.34 0.91 <NA> 2011-12-05 2011-12-19 13.00000 14.00000 13.00000 0
1387 0010000873 1 2011-12-19 834.00000 0.31 0.91 <NA> 2011-12-05 2011-12-20 14.00000 15.00000 14.00000 0
1391 0010000873 1 2011-12-20 834.00000 0.62 0.91 <NA> 2011-12-05 2011-12-27 15.00000 22.00000 15.00000 0
1411 0010000873 1 2011-12-27 834.00000 0.61 1.44 <NA> 2011-12-05 2011-12-31 22.00000 26.00000 22.00000 0
1418 0010000873 1 2011-12-31 834.00000 0.43 1.18 <NA> 2011-12-05 2012-01-01 26.00000 27.00000 26.00000 0
1419 0010000873 1 2012-01-01 834.00000 0.46 1.22 <NA> 2011-12-05 2013-07-09 27.00000 581.95833 27.00000 0
1466 0010000873 1 2013-07-09 834.00000 0.85 0.91 <NA> 2011-12-05 2014-03-18 581.95833 834.00000 581.95833 0
1478 0010000873 1 2014-03-18 834.00000 1.20 1.00 <NA> 2011-12-05 2015-09-18 834.00000 1382.95833 834.00000 0
2020 0010002412 1 2015-03-26 23.95833 1.16 0.85 <NA> 2015-03-26 2015-04-10 0.00000 14.95833 0.00000 0
2035 0010002412 1 2015-04-10 23.95833 0.67 0.74 <NA> 2015-03-26 2015-04-14 14.95833 18.95833 14.95833 0
2043 0010002412 1 2015-04-14 23.95833 0.56 0.75 <NA> 2015-03-26 2015-04-16 18.95833 20.95833 18.95833 0
2046 0010002412 1 2015-04-16 23.95833 0.45 0.75 <NA> 2015-03-26 2015-04-17 20.95833 21.95833 20.95833 0
2049 0010002412 1 2015-04-17 23.95833 0.52 0.86 <NA> 2015-03-26 2015-04-18 21.95833 22.95833 21.95833 0
这是我使用的代码:
copd.id <- DATA[!duplicated(DATA$patnr),]
copd.id$event <- as.numeric(!is.na(copd.id$deathdate))
lmeFit.copd <- lme(CysC~obstime+obstime:sex, random=~obstime|patnr, data=DATA)
coxFit.copd <- coxph(Surv(time,event)~sex, data=copd.id, x=TRUE)
jointFit.copd <- jointModel(lmeFit.copd, coxFit.copd, timeVar="obstime",method="piecewise-PH-aGH")
summary(jointFit.copd)
我收到以下错误消息:
jointFit.copd <- jointModel(lmeFit.copd, coxFit.copd, timeVar="obstime",method="piecewise-PH-aGH") Fehler in jointModel(lmeFit.copd, coxFit.copd, timeVar = "obstime", method = "piecewise-PH-aGH") : it seems that there are longitudinal measurements taken after the event times for some subjects (i.e., check subject(s): 0010000343, 0010000695, 0010000873, 0010002412, 0010002782, 0010003305, 0010003865, 0010003975, 0010004179, 0010004534, 0010004943, 0010005724, 0010007075, 0010007495, 0010008083, 0010008279, 0010008488, 0010008692, 0010008751, 0010009439, 0010010330, 0010011663, 0010012262, 0010012543, 0010012575, 0010013477, 0010014195, 0010015876, 0010016684, 0010017677, 0010018443, 0010019213, 0010019403, 0010019646, 0010020446, 0010020695, 0010021115, 0010021159, 0010021916, 0010022698, 0010024937, 0010026652, 0010030656, 0010031115, 0010031654, 0010031760, 0010033685, 0010034046, 0010034303, 0010035140, 0010037655, 0010038043, 0010038117, 0010038168, 0010038622, 0010039907, 0010042346, 0010044178, 0010046528, 0010046756, 0010048385, 0010049308, 0010049625, 0010049854, 0010050309, 0010051869, 0010052193, 0010052645, 0010052927, 0010053024, 0010054182, 0010055882, 001
summary(jointFit.copd) Fehler in summary(jointFit.copd) : Objekt 'jointFit.copd' nicht gefunden
问题是:我检查了数据,事件发生后没有测量值。
我在这里错过了什么?
尝试在 运行 模型之前对 patnr
进行排序 DATA
。我可以通过制作一个未排序的 newid
来引发您在 aids
示例中为 DATA
得到的错误。
library(JM)
is.unsorted(aids$patient)
length(unique(aids$patient))
## make newid that is unsorted
no.rows <- rle(c(aids$patient))
aids$newid <- paste0(rep( rep(LETTERS, length.out=467), no.rows$lengths), aids$patient)
is.unsorted(aids$newid)
length(unique(aids$newid))
## change `patient` to newid in the following lines to get
## error message for `jointFit.aids`
aids.id <- aids[!duplicated(aids$patient),]
lmeFit.aids <- lme(CD4~obstime + obstime:drug, random=~obstime|newid, data=aids)
coxFit.aids <- coxph(Surv(Time,death)~drug,data=aids.id, x=TRUE)
jointFit.aids <- jointModel(lmeFit.aids, coxFit.aids, timeVar="obstime",method="piecewise-PH-aGH")
summary(jointFit.aids)
当我看到 code for JM on github 时,我想到了这个。由于错误消息打印在 jointModel.R 中的第 139 行,我查看了该行上方的内容是如何定义的,并得出结论,假设数据集是根据 id 变量排序的。因此,虽然 DATA
中没有任何主题违反条件,但顺序在代码中被打乱了。在没有可重现示例的情况下,我的第一个提示是问题中给出的数据集的前 20 行的 ID 为 0010000343、0010000873、0010002412,但发布的错误消息列出了按排序顺序排列的 ID 为 0010000343,0010000695, 0010000873, 0010002412 -- 表示 DATA
未按 lme()
模型中列出的 id 变量 (patnr
) 排序。原始 aids
示例按 id (patient
).