mcmodel: Specify a Monte Carlo Model

View source: R/mcmodel.R

mcmodelR Documentation

Specify a Monte Carlo Model

Description

Specifies a ‘⁠mcmodel⁠’ without evaluating it, for subsequent evaluation using evalmcmod.

Usage

mcmodel(x, is.expr = FALSE)

Arguments

x

an R call or an expression.

is.expr

‘⁠FALSE⁠’ to send a call, ‘⁠TRUE⁠’ to send an expression.

Details

The model should be put between ‘⁠{⁠’ and ‘⁠}⁠’. The last line should be of the form ‘⁠mc(...)⁠’. Any reference to the number of simulations in the variability dimension should use ‘⁠ndvar()⁠’ or (preferred) ‘⁠nsv⁠’. Any reference to the number of simulations in the uncertainty dimension should use ‘⁠ndunc()⁠’ or (preferred) ‘⁠nsu⁠’.

Value

an R expression of class ‘⁠mcmodel⁠’.

See Also

expression, evalmcmod to evaluate the model, mcmodelcut to evaluate in a loop.

Examples

modEC1 <- mcmodel({
  conc <- mcdata(10, "0")
  cook <- mcstoc(rempiricalD, values=c(0, 1/5, 1/50), prob=c(0.027, 0.373, 0.600))
  serving <- mcstoc(rgamma, shape=3.93, rate=0.0806)
  expo <- conc * cook * serving
  dose <- mcstoc(rpois, lambda=expo)
  risk <- 1 - (1 - 0.001)^dose
  mc(conc, cook, serving, expo, dose, risk)
})
evalmcmod(modEC1, nsv=100, nsu=100)

mc2d documentation built on Oct. 23, 2026, 1:06 a.m.