People of R(th),
I have been ramming my head against this problem, and I wondered if
anyone could lend a hand. I want to parallelize a bootstrap of a linear
model on my 8-core mac. Below is the process that I want to parallelize
(namely, the m2.ph.rlm.boot<-boot(m2.ph,m2.ph.fun, R = nboot) command).
This is an extension of the bootstrapping linear models example in
Venables and Ripley to lmer. Please excuse my rather terrible
programming skills. I am always open to suggestions. Below the example I
describe what methods I have tried (which is the reason for all of the
unnecessary library calls).
>library(snow)
library(snowfall)
library(boot)
library(lme4)
library(multicore)
library(rlecuyer)
dat<-read.table("http://www2.fiu.edu/~adick/downloads/toy2.dat",
header = T)
nboot<-1000
attach(dat)
x<-dat[,2]
y<-dat[,4]
z<-dat[,3]
subj<-dat[,1]
m2.ph.fun<-function(data,i) {
d<-data
d$y<- d$fitted+d$res[i]
as.numeric(coef(update(m2.fit,data=d))[1][[1]][1,c(1:4)])
}
m2.fit<-lmer(y~x*z + (1|(subj)))
m2.prep<-na.omit(cbind(y,x,z,subj))
m2.ph<-data.frame(m2.prep, res=resid(m2.fit), fitted=fitted(m2.fit))
m2.ph.rlm.boot<-boot(m2.ph,m2.ph.fun, R = nboot)
Methods attempted:
Using the multicore package, I tried
m2.ph.rlm.boot<-collect(parallel(boot(m2.ph,m2.ph.fun, R = nboot))).
This returned a correct result, but did not speed things up. Not sure why...
I also tried snowfall and snow. While I can create a cluster and run
simple processes (e.g., provided example from literature), I can't get
the bootstrap to run. For example, using snow:
cl <- makeCluster(8)
clusterSetupRNG(cl)
clusterEvalQ(cl,library(boot))
clusterEvalQ(cl,library(lme4))
m2.ph.rlm.boot<-clusterCall(cl,boot(m2.ph,m2.ph.fun, R = nboot))
stopCluster()
returns the following error:
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
8 nodes produced errors; first error: could not find function "fun"
I am stuck and at the limit of my programming knowledge and am punting
to the R-help list. Any suggestions are much appreciated.
Anthony
--
Anthony Steven Dick, Ph.D.
Assistant Professor
Department of Psychology
Florida International University
Modesto A. Maidique Campus DM 296B
11200 S.W. 8th Street
Miami, FL 33199
Phone: 305-348-4202
Lab Phone: 305-348-9057 or 305-348-9055 (I am usually here)
Fax: 305-348-3879
Email: adick at fiu.edu
Webpage: http://www.fiu.edu/~adick