mccut: Evaluates a Two-Dimensional Monte Carlo Model in a Loop

mccutR Documentation

Evaluates a Two-Dimensional Monte Carlo Model in a Loop

Description

‘⁠evalmccut⁠’ evaluates a Two-Dimensional Monte Carlo model using a loop on the uncertainty dimension. Within each loop, it calculates statistics in the variability dimension and stores them for further analysis. It allows evaluation of very high dimension models using time instead of memory.

Builds a ‘⁠mcmodelcut⁠’ object that can be sent to evalmccut.

Usage

evalmccut(model, nsv = ndvar(), nsu = ndunc(), seed = NULL, ind = "index")

mcmodelcut(x, is.expr = FALSE)

## S3 method for class 'mccut'
plot(
  x,
  stat = c("median", "mean"),
  lim = c(0.025, 0.25, 0.75, 0.975),
  griddim = NULL,
  xlab = names(x),
  ylab = "Fn(x)",
  main = "",
  draw = TRUE,
  ...
)

## S3 method for class 'mccut'
print(x, lim = c(0.025, 0.975), digits = 3, ...)

Arguments

model

a ‘⁠mcmodelcut⁠’ object or a valid call including three blocks.

nsv

the number of simulations for variability.

nsu

the number of simulations for uncertainty.

seed

the random seed. If ‘⁠NULL⁠’ the seed is unchanged.

ind

the variable name used in ‘⁠model⁠’ to refer to the uncertainty loop index.

x

for mcmodelcut: a call or an expression (if is.expr=TRUE) including three blocks (see Details and Examples for the required structure). For print.mccut and plot.mccut: an ‘⁠mccut⁠’ object.

is.expr

FALSE to send a call, TRUE to send an expression (see mcmodel examples).

stat

a character string: "median" (default) or "mean", the statistic used to display the uncertainty in the plot.

lim

a vector of quantiles for the uncertainty dimension. For print.mccut defaults to c(0.025, 0.975); for plot.mccut defaults to c(0.025, 0.25, 0.75, 0.975).

griddim

a vector of two integers specifying the grid layout (rows, columns) for the plot. If NULL, the grid is computed automatically.

xlab

a vector of x-axis labels, one per node. Defaults to the names of the ‘⁠mccut⁠’ object.

ylab

the y-axis label.

main

the plot title.

draw

logical. If TRUE (default), the plot is drawn. Set to FALSE when calling from within evalmccut to store the plot data.

...

additional arguments passed to the print or plot function.

digits

number of digits in the print.

Details

‘⁠x⁠’ (or ‘⁠model⁠’) should be built as three blocks, separated by ‘⁠{⁠’:

  1. The first block is evaluated once (and only once) before the loop. It should evaluate all ‘⁠"V"⁠’, ‘⁠"0"⁠’ and ‘⁠"U"⁠’ nodes.

  2. The second block, which should lead to an ‘⁠mc⁠’ object, is evaluated using ‘⁠nsu=1⁠’. It must end with an expression like ‘⁠mymc <- mc(...)⁠’.

  3. The third block is evaluated on the ‘⁠mc⁠’ object. All resulting statistics are stored. It should build a list of statistics such as ‘⁠summary⁠’, ‘⁠plot⁠’, ‘⁠tornado⁠’ or any function leading to a vector, matrix or list of those.

Steps 2 and 3 are repeated ‘⁠nsu⁠’ times. At each iteration, the loop index (from 1 to ‘⁠nsu⁠’) is assigned to the variable specified in ‘⁠ind⁠’.

Value

An object of class ‘⁠mccut⁠’.

Note

The seed is set at the beginning of the evaluation. Complete similarity of two evaluations with the same seed is not certain depending on the model structure. In particular, the results will differ from evalmcmod with the same seed. Do not use upper case variables in your model to avoid conflicts with internal variables.

See Also

evalmcmod, mcmodelcut.

Examples

modEC3 <- mcmodelcut({
## First block: evaluates all 0, V and U nodes
  {
    cook <- mcstoc(rempiricalD, type="V", values=c(0, 1/5, 1/50), prob=c(0.027, 0.373, 0.6))
    serving <- mcstoc(rgamma, type="V", shape=3.93, rate=0.0806)
    conc <- mcstoc(rnorm, type="U", mean=10, sd=2)
    r <- mcstoc(runif, type="U", min=5e-04, max=0.0015)
  }
## Second block: evaluates VU nodes, leads to mc object
  {
    expo <- conc * cook * serving
    dose <- mcstoc(rpois, type="VU", lambda=expo)
    risk <- 1 - (1 - r)^dose
    res <- mc(conc, cook, serving, expo, dose, r, risk)
  }
## Third block: statistics
  {
    list(
      sum = summary(res),
      plot = plot(res, draw=FALSE),
      minmax = lapply(res, range)
    )
  }
})

x <- evalmccut(modEC3, nsv=101, nsu=101, seed=666)
summary(x)

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