Skip to contents

Multi-core replicate. Use multiple cores for repeated evaluation of an expression.

Usage

mcReplicate(n, expr, mc.cores = 4, refresh = 0.1)

Arguments

n

integer; the number of replications.

expr

the expression (a language object, usually a call) to evaluate n times.

mc.cores

number of cores to use.

refresh

status update refresh interval.

Value

A vector, matrix, or list of length `n`.

Examples

one_sim = \(n = 100, control_prob = 0.1, rel_effect = 0.01) {
  treat_prob = control_prob + (control_prob * rel_effect)
  cy = rbinom(n = n, size = 1, prob = control_prob)
  ty = rbinom(n = n, size = 1, prob = treat_prob)
  mean(ty) - mean(cy)
}
mcReplicate(10, one_sim(), mc.cores = 2)
#> 
#>  [1]  0.08  0.01  0.03  0.01 -0.01  0.07  0.02 -0.03 -0.03  0.02