data(beets)
head(beets)
beet0 <- lmer(sugpct ~ block + sow + harvest + (1|block:harvest), data=beets, REML=FALSE)
beet_no.harv <- update(beet0, . ~ . -harvest)
rd <- PBrefdist(beet0, beet_no.harv, nsim=20, cl=1)
rd
if (FALSE) {
## Note: Many more simulations must be made in practice.
# Computations can be made in parallel using several processors:
# 1: On OSs that fork processes (that is, not on windows):
# --------------------------------------------------------
if (Sys.info()["sysname"] != "Windows"){
N <- 2 ## Or N <- parallel::detectCores()
# N cores used in all calls to function in a session
options("mc.cores"=N)
rd <- PBrefdist(beet0, beet_no.harv, nsim=20)
# N cores used just in one specific call (when cl is set,
# options("mc.cores") is ignored):
rd <- PBrefdist(beet0, beet_no.harv, nsim=20, cl=N)
}
# In fact, on Windows, the approach above also work but only when setting the
# number of cores to 1 (so there is to parallel computing)
# In all calls:
# options("mc.cores"=1)
# rd <- PBrefdist(beet0, beet_no.harv, nsim=20)
# Just once
# rd <- PBrefdist(beet0, beet_no.harv, nsim=20, cl=1)
# 2. On all platforms (also on Windows) one can do
# ------------------------------------------------
library(parallel)
N <- 2 ## Or N <- detectCores()
clus <- makeCluster(rep("localhost", N))
# In all calls in a session
options("pb.cl"=clus)
rd <- PBrefdist(beet0, beet_no.harv, nsim=20)
# Just once:
rd <- PBrefdist(beet0, beet_no.harv, nsim=20, cl=clus)
stopCluster(clus)
}
Run the code above in your browser using DataLab