我試圖運行下面的代碼並行格式(用於EWAS目的):doParallel似乎破壞輸出不明原因
registerDoParallel(2)
combined <- foreach(i = 28:78, .combine=rbind) %dopar%
{
mm<-rep(NA,412)
FIDunique<-unique(pheno$FID)
for(j in FIDunique)
{
nn<-which(pheno1$FID==j)
mm[nn]<-mean(pheno1[nn,i])
}
tt4<-which(!is.na(mm))
if(length(tt4)>19 & length(table(pheno1[,i]))>1)
{
meth<-pheno1[tt4,i]
mm<-mm[tt4]
if(length(levels(factor(pheno1$smoking)))<2)
{
lme2<-tryCatch(lme(I(meth-mm)~delta_residSpine+I(DNA_year-AGE_year)+CD8T+CD4T+NK+Bcell+Mono+Gran,random=~1|FID, control=lmeControl(msMaxIter=50000,opt="optim"), data=pheno1[tt4,]),error = function(e) rep (NaN,1))
}
else
{
lme2<-tryCatch(lme(I(meth-mm)~delta_residSpine+I(DNA_year-AGE_year)+factor(smoking)+CD8T+CD4T+NK+Bcell+Mono+Gran,random=~1|FID, control=lmeControl(msMaxIter=50000,opt="optim"), data=pheno1[tt4,]),error = function(e) rep (NaN,1))
}
if(!is.na(lme2)) out18[i-27,2:5]<-summary(lme2)$tTable[2,-3]
rm(mm,nn,meth,lme2)
}
out18[i-27,6]<-length(tt4)
out18[i-27,]
}
我遇到的問題是,當我使用%但是當我使用%dopar%(如上面的代碼所示)時,the middle four columns of combined dissapear.我想這是由於這四列是基於tryCatch分配?我一直堅持這幾天,真的需要取得進展。
這也是值得什麼,當我運行該程序作爲%的人%,我得到警告
警告在如果out18 [我 - 27,2(is.na(lme2)!): 5] < - 摘要(lme2)$ TTable的[2,1: 條件具有長度> 1且只有第一元件將用於每次迭代中使用
,但我不下運行時得到這在所有%dopar%。
道歉,如果我還沒有給出足夠的信息關於變量是什麼,我試圖儘可能少地披露出於道德原因正在處理的實際信息。
它不容易跟隨你的問題。你在做什麼Os? '%do%'和'%dopar%'絕對沒有相同的行爲,'%dopar%'可以依賴於Os。 – clemlaflemme
您的問題可能來自您嘗試在使用'foreach'(即out18'數組)時更新一個值,這是沒有意義的。嘗試使用新的矢量,並只返回它。 '.combine'選項將正確地捕獲結果 – clemlaflemme