# NOT RUN {
## Approximative (Monte Carlo) Cochran-Mantel-Haenszel test
## Serial operation
set.seed(123)
cmh_test(disease ~ smoking | gender, data = alzheimer,
distribution = approximate(nresample = 100000))
# }
# NOT RUN {
## Multicore with 8 processes (not for MS Windows)
set.seed(123, kind = "L'Ecuyer-CMRG")
cmh_test(disease ~ smoking | gender, data = alzheimer,
distribution = approximate(nresample = 100000,
parallel = "multicore", ncpus = 8))
## Automatic PSOCK cluster with 4 processes
set.seed(123, kind = "L'Ecuyer-CMRG")
cmh_test(disease ~ smoking | gender, data = alzheimer,
distribution = approximate(nresample = 100000,
parallel = "snow", ncpus = 4))
## Registered FORK cluster with 12 processes (not for MS Windows)
fork12 <- parallel::makeCluster(12, "FORK") # set-up cluster
parallel::setDefaultCluster(fork12) # register default cluster
set.seed(123, kind = "L'Ecuyer-CMRG")
cmh_test(disease ~ smoking | gender, data = alzheimer,
distribution = approximate(nresample = 100000,
parallel = "snow"))
parallel::stopCluster(fork12) # clean-up
## User-specified PSOCK cluster with 8 processes
psock8 <- parallel::makeCluster(8, "PSOCK") # set-up cluster
set.seed(123, kind = "L'Ecuyer-CMRG")
cmh_test(disease ~ smoking | gender, data = alzheimer,
distribution = approximate(nresample = 100000,
parallel = "snow", cl = psock8))
parallel::stopCluster(psock8) # clean-up
# }
Run the code above in your browser using DataLab