2

我正在尝试使用模拟数据执行联合模型分析。我相信我已正确格式化数据,但收到此错误:

“jointModel(lmeFitJ, coxFit, timeVar = "time.point") 中的错误:纵向和事件过程中的样本大小不同;也许您忘记了 cluster() 参数。”

我只在 JM 的源代码和一个简短且未解决的故障排除线程中看到这一点。我哪里搞砸了?感谢您的任何帮助!

前 4 名参与者的最小完整示例:

#required packages
library(readxl, nlme, JM)

#long_data
structure(list(particip.id = c(1, 1, 1, 1, 2, 2, 3, 4, 4, 4, 
4), time.point = c(1, 2, 3, 4, 1, 2, 1, 1, 2, 3, 4), school4me = c("DPU", 
"DPU", "DPU", "DPU", "DPU", "DPU", "DPU", "DPU", "DPU", "DPU", 
"DPU"), hours.a = c(3, 3, 2, 3, 0, 0, 6, 10, 13, 16, 15), hours.b = c(4, 
6, 0, 0, 0, 1, 3, 7, 15, 9, 10), enrolled = c(1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1), TimeQ = c(4, 4, 4, 4, 2.9369807105977, 2.9369807105977, 
1.50240888306871, 4, 4, 4, 4)), row.names = c(NA, -11L), class = c("tbl_df", 
"tbl", "data.frame"))

#short_data
structure(list(particip.id = c(1, 2, 3, 4), time.point = c(3, 
2, 3, 4), school4me = c("DPU", "DPU", "DPU", "DPU"), enrolled = c(0, 
0, 0, 1), TimeQ = c(2.376576055, 1.152660467, 2.300307851, 4), 
actual = c(1, 1, 1, 0)), row.names = c(NA, -4L), class = c("tbl_df", 
"tbl", "data.frame"))

#Analysis
lmeFitJ <- lme(hours.a ~ time.point + time.point:school4me, data=long_data, random = ~time.point | particip.id)
coxFit <- coxph(Surv(TimeQ, actual) ~ school4me, data = short_data, x = TRUE)
fitJOINT <- jointModel(lmeFitJ, coxFit, timeVar = "time.point")
#analysis produces: "Error in jointModel(lmeFitJ, coxFit, timeVar = "time.point") : sample sizes in 
#the longitudinal and event processes differ; maybe you forgot the cluster() argument."
4

1 回答 1

0

在源代码中你可以找到

if (is.null(survObject$model))
stop("\nplease refit the Cox model including in the ", 
"call to coxph() the argument 'model = TRUE'.")

nT <- length(unique(idT))
if (LongFormat && is.null(survObject$model$cluster))
stop("\nuse argument 'model = TRUE' and cluster() in coxph().")

不幸的是,纵向过程警告首先发生,因此您看不到它们。

    ("sample sizes in the longitudinal and event processes differ; ", 
    "maybe you forgot the cluster() argument.\n")

尝试将model = TRUE和添加cluster(particip.id)到您的coxFitie coxFit <- coxph(Surv(TimeQ, actual) ~ school4me + cluster(particip.id), data = short_data, x = TRUE, model = TRUE)

于 2020-09-16T08:36:37.423 回答