Learn R Programming

tgp (version 2.4-23)

sens: Monte Carlo Bayesian Sensitivity Analysis

Description

Fully Bayesian Monte Carlo sensitivity analysis scheme, based upon any of the regression models contained in the tgp package. Random Latin hypercube samples are drawn at each MCMC iteration in order to estimate main effects as well as 1st order and total sensitivity indices.

Usage

sens(X, Z, nn.lhs, model = btgp, ngrid = 100, span = 0.3,
     BTE = c(3000,8000,10), rect = NULL, shape = NULL, mode = NULL,
     ...)

Value

The output is a "tgp"-class object. The details for btgp

contain a complete description of this output. The list entry that is relevance to sensitivity analysis is sens, which itself has entries:

par

This contains a list of the input parameters used in the sensitivity analysis, as outlined above.

Xgrid

A matrix containing a grid in each input dimension (by column) over which the main effects are estimated.

ZZ.mean

A matrix, where each column contains the mean main effects over the corresponding column of sens.Xgrid.

ZZ.q1

A matrix, where each column contains the 5th percentile main effects over the corresponding column of sens.Xgrid.

ZZ.q2

A matrix, where each column contains the 5th percentile main effects over the corresponding column of sens.Xgrid.

S

A matrix, where each column contains the posterior sample of 1st order sensitivity indices for the corresponding input dimension.

T

A matrix, where each column contains the posterior sample of total sensitivity indices for the corresponding input dimension.

Arguments

X

data.frame, matrix, or vector of inputs X

Z

Vector of output responses Z of length equal to the leading dimension (rows) of X, i.e., length(Z) == nrow(X)

nn.lhs

Size of each Latin hypercube drawn for use in the Monte Carlo integration scheme. Total number of locations for prediction is nn.lhs*(ncol(X)+2)

model

Either the regression model used for prediction, or NULL. If model=NULL, then the function just returns the sens.p vector of parameters to be passed with a regression model call. This can be used to perform sensitivity analysis through the predict.tgp framework

ngrid

The number of grid points in each input dimension upon which main effects will be estimated.

span

Smoothing parameter for main effects integration: the fraction of nn.lhs points that will be included in a moving average window that is used to estimate main effects at the ngrid locations in each input dimension.

BTE

3-vector of Monte-Carlo parameters (B)urn in, (T)otal, and (E)very. Predictive samples are saved every E MCMC rounds starting at round B, stopping at T

rect

Rectangle describing the domain of the uncertainty distribution with respect to which the sensitivity is to be determined. This defines the domain from which the LH sample is to be taken. The rectangle should be a matrix or data.frame with ncol(rect) = 2, and number of rows equal to the dimension of the domain. For 1-d data, a vector of length 2 is allowed. Defaults to the input data range (X).

shape

Optional vector of shape parameters for the Beta distribution. Vector of length equal to the dimension of the domain, with elements > 1. If specified, the uncertainty distribution (i.e. the LH sample) is proportional to a joint pdf formed by independent Beta distributions in each dimension of the domain, scaled and shifted to have support defined by rect. Only concave Beta distributions with shape > 1 are supported. If unspecified, the uncertainty distribution is uniform over rect. The specification shape[i]=0 instructs sens to treat the i'th dimension as a binary variable. In this case, mode[i] is the probability parameter for a bernoulli uncertainty distribution, and we must also have rect[i,]=c(0,1).

mode

Optional vector of mode values for the Beta uncertainty distribution. Vector of length equal to the dimension of the domain, with elements within the support defined by rect. If shape is specified, but this is not, then the scaled Beta distributions will be symmetric.

...

Extra arguments to the tgp model.

Author

Robert B. Gramacy, rbg@vt.edu, and Matt Taddy, mataddy@amazon.com

Details

Saltelli (2002) describes a Latin Hypercube sampling based method for estimation of the 'Sobal' sensitivity indices:

1st Order for input \(i\), $$S(i) = \mbox{Var}(E[f|x_i])/\mbox{Var}(f),$$ where \(x_i\) is the \(i\)-th input.

Total Effect for input \(i\), $$T(i) = E[\mbox{Var}(f|x_{-i})]/\mbox{Var}(f),$$ where \(x_{-i}\) is all inputs except for the \(i\)-th.

All moments are with respect to the appropriate marginals of the uncertainty distribution \(U\) -- that is, the probability distribution on the inputs with respect to which sensitivity is being investigated. Under this approach, the integrals involved are approximated through averages over properly chosen samples based on two LH samples proportional to U. If nn.lhs is the sample size for the Monte Carlo estimate, this scheme requires nn.lhs*(ncol(X)+2) function evaluations.

The sens function implements the method for unknown functions \(f\), through prediction via one of the tgp regression models conditional on an observed set of X locations. At each MCMC iteration of the tgp model fitting, the nn.lhs*(ncol(X)+2) locations are drawn randomly from the LHS scheme and realizations of the sensitivity indices are calculated. Thus we obtain a posterior sample of the indices, incorporating variability from both the Monte Carlo estimation and uncertainty about the function output. Since a subset of the predictive locations are actually an LHS proportional to the uncertainty distribution, we can also estimate the main effects through simple non-parametric regression (a moving average).

Please see vignette("tgp2") for a detailed illustration

References

Gramacy, R. B. (2020) Surrogates: Gaussian Process Modeling, Design and Optimization for the Applied Sciences. Boca Raton, Florida: Chapman Hall/CRC. (See Chapter 8.) https://bobby.gramacy.com/surrogates/

R.D. Morris, A. Kottas, M. Taddy, R. Furfaro, and B. Ganapol. (2009) A statistical framework for the sensitivity analysis of radiative transfer models. IEEE Transactions on Geoscience and Remote Sensing, to appear.

Saltelli, A. (2002) Making best use of model evaluations to compute sensitivity indices. Computer Physics Communications, 145, 280-297.

See Also

btgp, plot.tgp, predict.tgp, lhs

Examples

Run this code
# Take a look at the air quality in New York: Sensitivity of
# ozone levels with respect to solar radiation, wind, and
# temperature. See help(airquality) for details.  
X <- airquality[,2:4]
Z <- airquality$Ozone

# Uncertainty distribution is the default: uniform over range(X)
# There is missing data, which is removed automatically by tgp
# range(X).
# \donttest{
s <- suppressWarnings(sens(X=X, Z=Z, nn.lhs=300, model=btgp,
          ngrid=100, span=0.3, BTE=c(5000,10000,10)))

# plot the results
plot(s, layout="sens", ylab="Ozone", main="main effects") 

# plot only the sensitivity indices
plot(s, layout="sens", ylab="Ozone", maineff=FALSE) 

# plot only the main effects, side by side
plot(s, layout="sens", ylab="Ozone", main="", maineff=t(1:3))
# }

# build a 'sens.p' parameter vector for a data-dependent
# informative uncertainty distribution.  For each variable,
# the input distribution will be a scaled Beta with shape=2,
# and mode equal to the data mean
rect <- t(apply(X, 2, range, na.rm=TRUE))
mode <- apply(X , 2, mean, na.rm=TRUE)
shape <- rep(2,3)

# plot a sample from the marginal uncertainty distribution.
Udraw <- lhs(300, rect=rect, mode=mode, shape=shape)
par(mfrow=c(1,3))
for(i in 1:3) hist(Udraw[,i], breaks=15,xlab=names(X)[i]) 

# build sens.p with the 'sens' function.
sens.p <- suppressWarnings(sens(X=X, Z=Z, nn.lhs=300, model=NULL,
               ngrid=100, rect=rect, shape=shape, mode=mode))

# Use predict.tgp to quickly analyze with respect to this new
# uncertainty distribution without re-running the MCMC, then
# plot the results.
# \donttest{
s.new <- predict(s, BTE=c(1,1000,1), sens.p=sens.p, verb=1) 
plot(s.new, layout="sens", ylab="Ozone", main="main effects")
# }

Run the code above in your browser using DataLab