我尝试进行 10 倍交叉验证并通过使用并行处理(parLapply)来估计联合模型的模型性能。我试图找出我收到错误消息的原因:“checkForRemoteErrors(val) 中的错误:五个节点产生错误:找不到对象‘周’”
代码如下所示:
# Validation using 10-fold CV
library("parallel")
set.seed(123)
V <- 10
n <- nrow(dfC)
splits <- split(seq_len(n), sample(rep(seq_len(V), length.out = n)))
CrossValJM <- function (i) {
library("JM")
library("nlme")
trainingData <- dfL[!dfL$ID %in% i, ]
trainingData_ID <- trainingData[!duplicated(trainingData$ID), ]
testingData <- dfL[dfL$ID %in% i, ]
lmeFit <- lme(DA ~ ns(Week, 2), data = trainingData,
random = ~ ns(Week, 2) | ID)
coxFit <- coxph(Surv(TT_event, Event) ~ Gender * Age, data =
trainingData_ID,
x = TRUE)
jointFit <- jointModel(lmeFit, coxFit, timeVar = "Week")
pe <- prederrJM(jointFit, newdata = testingData, Tstart = 10,
Thoriz = 20)
auc <- aucJM(jointFit, newdata = testingData, Tstart = 10,
Thoriz = 20)
list(pe = pe, auc = auc)
}
cl <- makeCluster(5)
res <- parLapply(cl, splits, CrossValJM)
stopCluster(cl)
函数本身被接受,但是在运行集群命令时我遇到了这个错误,它提到它无法识别函数中给出的对象..它们应该在函数本身中定义吗?还是我没有正确使用 parLapply 函数?
PS:数据如下(dfL 是一个长度为 ~ 1000 和 dfC ~ 200 的数据帧):
dfL <- data.frame(ID = c(1, 1, 1, 2, 2, 3), DA = c(0.4, 1.8, 1.2, 3.2, 3.6, 2.8), Week = c(0, 4, 16, 4, 20, 8), Event = c(1, 1, 1, 0, 0, 1), TT_Event = c(16, 20, 8), Gender = c(0, 0, 0, 1, 1, 0), Age = c(24, 24, 24, 56, 56, 76))
dfC <- data.frame(ID = c(1, 2, 3, 4, 5, 6), DA = c(1.2, 3.6, 2.8, 2.4, 1.9, 3.4), Week = c(16, 20, 8, 36, 24, 32), Event = c(1, 0, 1, 1, 1, 0), TT_Event = c(16, 20, 8, 36, 24, 32), Gender = c(0, 1, 0, 0, 1, 1), Age = c(24, 56, 76, 38, 44, 50))
谢谢 :)