"sample sizes in the longitudinal and event processes differ" in JointModel in r



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

"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."

在源代码中可以找到

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 = TRUEcluster(particip.id)添加到您的coxFit中,即。coxFit <- coxph(Surv(TimeQ, actual) ~ school4me + cluster(particip.id), data = short_data, x = TRUE, model = TRUE)

相关内容

  • 没有找到相关文章

最新更新