sem*_*uin 4 parallel-processing r
我正在使用boot函数R来实现bootstrap.我的问题是如何设置boot利用其并行选项.考虑以下估算中位数的具体示例.
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"))
Run Code Online (Sandbox Code Playgroud)
我不知道如何parallel在boot函数中使用该选项.让我们parallel = "multicore"不提高速度.我尝试过更复杂的估算问题.但我没有看到差异.所以我想我没有boot正确使用.我的机器是双核Mac.
从boot手册(粗体是我的).
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)
尝试:
system.time(boot(dat, med_est, R = 10000, parallel = "multicore", ncpus=2))
Run Code Online (Sandbox Code Playgroud)