Learn R Programming

pse (version 0.3.4)

LHS: Latin Hypercube Sampling for uncertainty and sensitivity analyses

Description

Generates the Latin Hypercube sampling for uncertainty and sensitivity analyses. A Latin Hypercube of size N is generated from the desired quantile distribution functions

The following methods are currently supported for generating the LHS: random LHS and Huntington & Lyrintzis method for correcting the correlation matrix to be similar to the prescribed by the option COR (see the arguments for description).

The specified model is run with the data from the LHS. If repetitions is set to more than one, the model will be run several times for each data point.

Partial rank correlation coefficients are estimated.

When the LHS function is called with no model (i.e., with argument model=NULL), it generates an incomplete object storing the Latin Hypercube samples, and allowing the user to run the simulation model independently. The method tell allows to pass the simulation results to the incomplete object.

The

Usage

LHS(model = NULL, factors, N, q = NULL, q.arg = NULL, res.names = NULL, 
	method=c("HL", "random"), opts=list(), nboot = 0, repetitions=1,
	cl = NULL)
## S3 method for class 'LHS':
tell(x, y, res.names = NULL, nboot = 0, \dots)
## S3 method for class 'LHS':
print(x, \dots)

Arguments

model
The function to be run, representing the model or simulation. If NULL, no function is run and the object generated is incomplete, see also the tell method.
factors
The names of the input variables (used for naming the 'data' data.frame and in plotting) Either a vector of strings or a single number representing the number of factors
N
The size of the hypercube, i.e., how many samples are generated. Must be at least the number of factors plus 2.
q
The quantile functions to be used. If only one is provided, it will be used for all parameters. Defaults to "qunif".
q.arg
A list containing the arguments for the 'q' functions. Each parameter must be specified by a named list, containing all of the arguments for the quantile distribution. If unsupplied, default values for the parameters are used.
res.names
Optional: what are the names of the model results? (Used mainly for plotting)
method
Currently, two methods are supported. "random" generates a simple LH, with no modifications. "HL" (the default) generates a random LH, and subsequently corrects the correlation matrix using the Huntington & Lyrintzis method.
opts
Further options for the method used. The method HL supports the following options: `COR' The desired correlation matrix between the model variables. If none is provided, the function will generate a zero-correlation Latin Hypercube. `eps' The t
nboot
Number of bootstrap replicates for calculating the PRCC.
repetitions
The number of model repetitions to be run for a single data point. See the vignette on stochastic models for details
cl
Cluster generated with the ``parallel'' library. May be of any type supported. If a cluster is provided, the model will be run in parallel or distributed across the cluster via clusterApply. No load balancing is provided, so the model results are re
x
An incomplete LHS object (created with model=NULL)
y
A data.frame containing the model responses
...
Currently ignored

Value

  • An object of the class LHS.

Warning

NOTE: the tell method from sensitivity objects (like 'fast99') modifies the object passed as argument as a side effect. This is NOT the case with the LHS tell method.

source

Uses internal code originally published on package sensitivity, by Gilles Pujol, Bertrand Iooss, Alexandre Janon

References

McKay, M.D. and Beckman, R.J. A comparison of three methods for selecting values of input variables in the analysis of output from a computer code, Technometrics. 1979, 21: 239-244

Examples

Run this code
completeLHS <- LHS(model=function(x) x[,1]+x[,2]*x[,3], factors=3, N=20)
incompleteLHS <- LHS(factors=5, N=30)
incompleteLHS <- tell(incompleteLHS, seq(1,30))

library(parallel)
	new.cluster = makePSOCKcluster(c("localhost", "localhost"))
	clusterLHS <- LHS(model=function(x) x[,1]/x[,2], factors=2, N=100, cl = new.cluster)
	stopCluster(new.cluster)

Run the code above in your browser using DataLab