mcstoc: Creates Stochastic mcnode Objects

View source: R/mcstoc.R

mcstocR Documentation

Creates Stochastic mcnode Objects

Description

Creates a mcnode object using a random generating function.

Usage

mcstoc(
  func = runif,
  type = c("V", "U", "VU", "0"),
  ...,
  nsv = ndvar(),
  nsu = ndunc(),
  nvariates = 1,
  outm = "each",
  nsample = "n",
  seed = NULL,
  rtrunc = FALSE,
  linf = -Inf,
  lsup = Inf,
  lhs = FALSE
)

Arguments

func

a function providing random data or its name as character.

type

the type of ‘⁠mcnode⁠’ to be built. By default, a ‘⁠"V"⁠’ node. See mcnode for details.

...

all other arguments but the size of the sample to be passed to ‘⁠func⁠’. These arguments should be vectors or ‘⁠mcnode⁠’s (arrays prohibited).

nsv

the number of simulations in the variability dimension.

nsu

the number of simulations in the uncertainty dimension.

nvariates

the number of variates of the output.

outm

the output of the ‘⁠mcnode⁠’ for multivariate nodes. May be ‘⁠"each"⁠’ (default), ‘⁠"none"⁠’, or a vector of function names (as character strings) applied on the variates dimension before output (e.g. ‘⁠"mean"⁠’, ‘⁠c("min","max")⁠’).

nsample

the name of the parameter of the function giving the size of the vector. By default ‘⁠"n"⁠’, as in most distributions of the stats library.

seed

the random seed used for the evaluation. If ‘⁠NULL⁠’ the seed is unchanged.

rtrunc

should the distribution be truncated? See rtrunc.

linf

if truncated: lower limit. May be a scalar, an array or a ‘⁠mcnode⁠’.

lsup

if truncated: upper limit. May be a scalar, an array or a ‘⁠mcnode⁠’. ‘⁠lsup⁠’ must be pairwise strictly greater than ‘⁠linf⁠’.

lhs

should a Latin Hypercube Sampling be used? See lhs.

Details

Any function that accepts vectors/matrices as arguments may be used (notably all current random generators of the stats package). Arguments may be sent classically, but it is strongly recommended to use consistent ‘⁠mcnode⁠’s if arguments should be recycled, since complex recycling is handled for ‘⁠mcnode⁠’ but not for vectors.

Compatibility rules for ‘⁠mcnode⁠’ arguments:

‘⁠type="V"⁠’

accepts ‘⁠"0" mcnode⁠’ of dim ‘⁠(1 x 1 x nvariates)⁠’ or ‘⁠(1 x 1 x 1)⁠’ (recycled) and ‘⁠"V" mcnode⁠’ of dim ‘⁠(nsv x 1 x nvariates)⁠’ or ‘⁠(nsv x 1 x 1)⁠’ (recycled).

‘⁠type="U"⁠’

accepts ‘⁠"0" mcnode⁠’ of dim ‘⁠(1 x 1 x nvariates)⁠’ or ‘⁠(1 x 1 x 1)⁠’ (recycled) and ‘⁠"U" mcnode⁠’ of dim ‘⁠(1 x nsu x nvariates)⁠’ or ‘⁠(1 x nsu x 1)⁠’ (recycled).

‘⁠type="VU"⁠’

accepts ‘⁠"0"⁠’, ‘⁠"V"⁠’, ‘⁠"U"⁠’ and ‘⁠"VU"⁠’ nodes with appropriate recycling rules.

‘⁠type="0"⁠’

accepts ‘⁠"0" mcnode⁠’ of dim ‘⁠(1 x 1 x nvariates)⁠’ or ‘⁠(1 x 1 x 1)⁠’ (recycled).

If ‘⁠rtrunc=TRUE⁠’, the distribution is truncated on ‘⁠(linf, lsup]⁠’. The function ‘⁠func⁠’ should have a ‘⁠q⁠’ form and a ‘⁠p⁠’ form.

If ‘⁠lhs=TRUE⁠’, a Latin Hypercube Sampling is used on ‘⁠nsv⁠’ and ‘⁠nsu⁠’. The function ‘⁠func⁠’ should have a ‘⁠q⁠’ form. Not allowed with multivariate distributions.

Value

An ‘⁠mcnode⁠’ object.

See Also

mcnode for a description of ‘⁠mcnode⁠’ objects. Ops.mcnode for operations on ‘⁠mcnode⁠’ objects. rtrunc for important warnings on the ‘⁠rtrunc⁠’ option.

Examples

Oldnvar <- ndvar()
Oldnunc <- ndunc()
ndvar(5)
ndunc(4)

## Compatibility with mcdata as arguments
x0 <- mcstoc(runif, type = "0")
xV <- mcstoc(runif, type = "V")
xU <- mcstoc(runif, type = "U")
xVU <- mcstoc(runif, type = "VU")

## "V" accepts "0" and "V" mcdata
mcstoc(rnorm, type = "V", mean = x0, sd = xV)

## "VU" accepts "0", "U", "V" and "VU" with correct recycling
mcstoc(rnorm, type = "VU", mean = xV, sd = xU)

ndvar(Oldnvar)
ndunc(Oldnunc)

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