I have to run thousands of models with thousands of outcomes. So I selected "foreach" and "doparallel" package to increase my speed. For the packages to analyze my data, I chose two different packages: "MASS" package and "lqmm" package. "MASS" package worked well, but "lqmm" package always came up with error. But I am thinking there might ways to deal with this issue by editing some statements in foreach function. I have searched all related questions in this aspect, but still get stuck. I hope someone could help me with it. Thanks in advance.
I tried to add ".packages" in the foreach function.
# read packages
library(foreach)
library(doParallel)
library(Formula)
# Parallel
cl <- makeCluster(5)
registerDoParallel(cl)
results <- foreach (i=1:10,.combine='rbind',.packages=c('lqmm')) %dopar% {
model <- lqmm(((eval(data)[,i] ~ AGE)), random=~1, group=id, data=data)
exposure="AGE"
pvalue=summary(model)$tTable[2.5]
want <- cbind(exposure, pvalue)
}
stopCluster(cl)
But I still got this error: Error in {: task 1 failed - "object 'i' not found"
I am guessing foreach doesn't understand i here (i.e., 1 to 10), but I don't know how to make foreach understand i here. It's not a variable/object, it's a loop changing from 1 to 10.
Can someone help me with it? Thank you.