lhs: Random Latin Hypercube Sampling

View source: R/lhs.R

lhsR Documentation

Random Latin Hypercube Sampling

Description

Creates a Latin Hypercube Sample (LHS) from the specified distribution.

Usage

lhs(distr = "runif", nsv = ndvar(), nsu = ndunc(), nvariates = 1, ...)

Arguments

distr

the function for generating random samples, or its name as a character string. If ‘⁠distr⁠’ is ‘⁠"rdist"⁠’, the quantile function ‘⁠"qdist"⁠’ must exist with argument ‘⁠p⁠’ as a vector of probabilities.

nsv

the number of rows of the final matrix.

nsu

the number of columns of the final matrix.

nvariates

the number of variates.

...

all arguments to be passed to ‘⁠distr⁠’ except the size of the sample.

Value

A vector of ‘⁠nsv x nsu x nvariates⁠’ random variates, stratified along the variability dimension (‘⁠nsv⁠’) for each column.

Note

The resulting LHS is a latin hypersquare sampling: the LHS structure is provided only in the first 2 dimensions. It is not possible to use truncated distributions directly with rtrunc. Use mcstoc with ‘⁠lhs=TRUE⁠’ and ‘⁠rtrunc=TRUE⁠’ for that purpose. The ... arguments will be recycled.

Adapted from a code by Rob Carnell (package lhs).

See Also

mcstoc

Examples

ceiling(lhs(runif, nsu=10, nsv=10) * 10)

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