Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use `parallel` option of `boot` function in `R`

I was using boot function in R to implement bootstrap. My question is how to set boot to exploit its parallel option. Consider the following concrete example of estimating median.

med_est <- function(dat, indices){
    .dat <- dat[indices]
    median(.dat)
}
dat <- rnorm(200)
system.time(boot(dat, med_est, R = 10000))
system.time(boot(dat, med_est, R = 10000, parallel = "multicore"))

I don't know how to use the parallel option in boot function. Letting parallel = "multicore" does not boost the speed at time. I have tried more complicated estimation problems. But I did not see the difference. So I guess I did not use boot correctly. My machine is double-core Mac.

like image 207
semibruin Avatar asked Mar 16 '23 10:03

semibruin


1 Answers

From the boot manual (bolding is mine).

boot(data, statistic, R, sim = "ordinary", stype = c("i", "f", "w"), strata = rep(1,n), L = NULL, m = 0, weights = NULL, ran.gen = function(d, p) d, mle = NULL, simple = FALSE, ..., parallel = c("no", "multicore", "snow"), ncpus = getOption("boot.ncpus", 1L), cl = NULL)

try:

system.time(boot(dat, med_est, R = 10000, parallel = "multicore", ncpus=2))
like image 90
Dean MacGregor Avatar answered Mar 28 '23 03:03

Dean MacGregor