{"id":416,"date":"2014-01-02T16:40:21","date_gmt":"2014-01-02T21:40:21","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=416"},"modified":"2014-01-02T16:40:21","modified_gmt":"2014-01-02T21:40:21","slug":"monte-carlo-bayesian-sensitivity-analysis","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/01\/02\/monte-carlo-bayesian-sensitivity-analysis\/","title":{"rendered":"Monte Carlo Bayesian Sensitivity Analysis"},"content":{"rendered":"<table summary=\"page for sens\" width=\"100%\">\n<tbody>\n<tr>\n<td>sens<\/td>\n<td align=\"right\">R Documentation<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Monte Carlo Bayesian Sensitivity Analysis<\/h2>\n<h3>Description<\/h3>\n<p>Fully Bayesian Monte Carlo sensitivity analysis scheme, based upon any of the regression models contained in the\u00a0tgp\u00a0package. 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.<\/p>\n<h3>Usage<\/h3>\n<pre>sens(X, Z, nn.lhs, model = btgp, ngrid = 100, span = 0.3,\n     BTE = c(3000,8000,10), rect = NULL, shape = NULL, mode = NULL,\n     ...)<\/pre>\n<h3>Arguments<\/h3>\n<table summary=\"R argblock\">\n<tbody>\n<tr valign=\"top\">\n<td><code>X<\/code><\/td>\n<td><code>data.frame<\/code>,\u00a0<code>matrix<\/code>, or vector of inputs\u00a0<code>X<\/code><\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>Z<\/code><\/td>\n<td>Vector of output responses\u00a0<code>Z<\/code>\u00a0of length equal to the leading dimension (rows) of\u00a0<code>X<\/code>, i.e.,\u00a0<code>length(Z) == nrow(X)<\/code><\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>nn.lhs<\/code><\/td>\n<td>Size of each Latin hypercube drawn for use in the Monte Carlo integration scheme. Total number of locations for prediction is\u00a0<code>nn.lhs*(ncol(X)+2)<\/code><\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>model<\/code><\/td>\n<td>Either the regression model used for prediction, or\u00a0<code>NULL<\/code>. If\u00a0<code>model=NULL<\/code>, then the function just returns the\u00a0<code>sens.p<\/code>\u00a0vector of parameters to be passed with a regression model call. This can be used to perform sensitivity analysis through the<code>predict.tgp<\/code>\u00a0framework<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>ngrid<\/code><\/td>\n<td>The number of grid points in each input dimension upon which main effects will be estimated.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>span<\/code><\/td>\n<td>Smoothing parameter for main effects integration: the fraction of\u00a0<code>nn.lhs<\/code>\u00a0points that will be included in a moving average window that is used to estimate main effects at the\u00a0<code>ngrid<\/code>\u00a0locations in each input dimension.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>BTE<\/code><\/td>\n<td>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<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>rect<\/code><\/td>\n<td>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\u00a0<code>matrix<\/code>\u00a0or\u00a0<code>data.frame<\/code>\u00a0with<code>ncol(rect) = 2<\/code>, 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 (<code>X<\/code>).<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>shape<\/code><\/td>\n<td>Optional vector of shape parameters for the Beta distribution. Vector of length equal to the dimension of the domain, with elements &gt; 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\u00a0<code>rect<\/code>. Only concave Beta distributions with\u00a0<code>shape<\/code>\u00a0&gt; 1 are supported. If unspecified, the uncertainty distribution is uniform over\u00a0<code>rect<\/code>. The specification\u00a0<code>shape[i]=0<\/code>\u00a0instructs\u00a0<code>sens<\/code>\u00a0to treat the i&#8217;th dimension as a binary variable. In this case,\u00a0<code>mode[i]<\/code>\u00a0is the probability parameter for a bernoulli uncertainty distribution, and we must also have\u00a0<code>rect[i,]=c(0,1)<\/code>.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>mode<\/code><\/td>\n<td>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\u00a0<code>rect<\/code>. If\u00a0<code>shape<\/code>\u00a0is specified, but this is not, then the scaled Beta distributions will be symmetric.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>...<\/code><\/td>\n<td>Extra arguments to the\u00a0tgp\u00a0<code>model<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Details<\/h3>\n<p>Saltelli (2002) describes a Latin Hypercube sampling based method for estimation of the &#8216;Sobal&#8217; sensitivity indices:<\/p>\n<p>1st Order for input\u00a0<i>i<\/i>,<\/p>\n<p align=\"center\"><i>S(i) = var(E[f|x[i]])\/var(f),<\/i><\/p>\n<p>where\u00a0<i>x[i]<\/i>\u00a0is the\u00a0<i>i<\/i>-th input.<\/p>\n<p>Total Effect for input\u00a0<i>i<\/i>,<\/p>\n<p align=\"center\"><i>T(i) = E[var(f|x[-i])]\/var(f),<\/i><\/p>\n<p>where\u00a0<i>x[-i]<\/i>\u00a0is all inputs except for the\u00a0<i>i<\/i>-th.<\/p>\n<p>All moments are with respect to the appropriate marginals of the uncertainty distribution\u00a0<i>U<\/i>\u00a0\u2013 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\u00a0<code>nn.lhs<\/code>\u00a0is the sample size for the Monte Carlo estimate, this scheme requires\u00a0<code>nn.lhs*(ncol(X)+2)<\/code>\u00a0function evaluations.<\/p>\n<p>The\u00a0<code>sens<\/code>\u00a0function implements the method for unknown functions\u00a0<i>f<\/i>, through prediction via one of the\u00a0tgp\u00a0regression models conditional on an observed set of\u00a0<code>X<\/code>\u00a0locations. At each MCMC iteration of the\u00a0tgp\u00a0model fitting, the\u00a0<code>nn.lhs*(ncol(X)+2)<\/code>\u00a0locations 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).<\/p>\n<p>Please see\u00a0<code>vignette(\"tgp2\")<\/code>\u00a0for a detailed illustration<\/p>\n<h3>Value<\/h3>\n<p>The output is a\u00a0<code>\"tgp\"<\/code>-class object. The details for\u00a0<code>btgp<\/code>\u00a0contain a complete description of this output. The list entry that is relevance to sensitivity analysis is\u00a0<code>sens<\/code>, which itself has entries:<\/p>\n<table summary=\"R valueblock\">\n<tbody>\n<tr valign=\"top\">\n<td><code>par<\/code><\/td>\n<td>This contains a\u00a0<code>list<\/code>\u00a0of the input parameters used in the sensitivity analysis, as outlined above.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>Xgrid<\/code><\/td>\n<td>A\u00a0<code>matrix<\/code>\u00a0containing a grid in each input dimension (by column) over which the main effects are estimated.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>ZZ.mean<\/code><\/td>\n<td>A\u00a0<code>matrix<\/code>, where each column contains the mean main effects over the corresponding column of\u00a0<code>sens.Xgrid<\/code>.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>ZZ.q1<\/code><\/td>\n<td>A\u00a0<code>matrix<\/code>, where each column contains the 5th percentile main effects over the corresponding column of\u00a0<code>sens.Xgrid<\/code>.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>ZZ.q2<\/code><\/td>\n<td>A\u00a0<code>matrix<\/code>, where each column contains the 5th percentile main effects over the corresponding column of\u00a0<code>sens.Xgrid<\/code>.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>S<\/code><\/td>\n<td>A\u00a0<code>matrix<\/code>, where each column contains the posterior sample of 1st order sensitivity indices for the corresponding input dimension.<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>T<\/code><\/td>\n<td>A\u00a0<code>matrix<\/code>, where each column contains the posterior sample of total sensitivity indices for the corresponding input dimension.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Note<\/h3>\n<p>The quality of sensitivity analysis is dependent on the size of the LH samples used for integral approximation; as with any Monte Carlo integration scheme, the sample size (<code>nn.lhs<\/code>) must increase with the dimensionality of the problem. The total sensitivity indices\u00a0<i>T<\/i>\u00a0are forced non-negative, and if negative values occur it is necessary to increase\u00a0<code>nn.lhs<\/code>. The\u00a0<code>plot.tgp<\/code>\u00a0function replaces negative values with zero for illustration.<\/p>\n<h3>Author(s)<\/h3>\n<p>Robert B. Gramacy,\u00a0<a href=\"mailto:rbgramacy@chicagobooth.edu\">rbgramacy@chicagobooth.edu<\/a>, and Matt Taddy,\u00a0<a href=\"mailto:taddy@chicagobooth.edu\">taddy@chicagobooth.edu<\/a><\/p>\n<h3>References<\/h3>\n<p>R.D. Morris, A. Kottas, M. Taddy, R. Furfaro, and B. Ganapol. (2009)\u00a0<em>A statistical framework for the sensitivity analysis of radiative transfer models.<\/em>\u00a0IEEE Transactions on Geoscience and Remote Sensing, to appear.<\/p>\n<p>Saltelli, A. (2002)\u00a0<em>Making best use of model evaluations to compute sensitivity indices.<\/em>\u00a0Computer Physics Communications, 145, 280-297.<\/p>\n<h3>See Also<\/h3>\n<p><code>btgp<\/code>,\u00a0<code>plot.tgp<\/code>,\u00a0<code>predict.tgp<\/code>,\u00a0<code>lhs<\/code><\/p>\n<h3>Examples<\/h3>\n<pre># Take a look at the air quality in New York: Sensitivity of\n# ozone levels with respect to solar radiation, wind, and\n# temperature. See help(airquality) for details.  \nX &lt;- airquality[,2:4]\nZ &lt;- airquality$Ozone\n\n# Uncertainty distribution is the default: uniform over range(X)\n# There is missing data, which is removed automatically by tgp\n# range(X).\ns &lt;- suppressWarnings(sens(X=X, Z=Z, nn.lhs=300, model=btgp,\n          ngrid=100, span=0.3, BTE=c(5000,10000,10)))\n\n# plot the results\nplot(s, layout=\"sens\", ylab=\"Ozone\", main=\"main effects\") \n\n# plot only the sensitivity indices\nplot(s, layout=\"sens\", ylab=\"Ozone\", maineff=FALSE) \n\n# plot only the main effects, side by side\nplot(s, layout=\"sens\", ylab=\"Ozone\", main=\"\", maineff=t(1:3))\n\n# build a 'sens.p' parameter vector for a data-dependent\n# informative uncertainty distribution.  For each variable,\n# the input distribution will be a scaled Beta with shape=2,\n# and mode equal to the data mean\nrect &lt;- t(apply(X, 2, range, na.rm=TRUE))\nmode &lt;- apply(X , 2, mean, na.rm=TRUE)\nshape &lt;- rep(2,3)\n\n# plot a sample from the marginal uncertainty distribution.\nUdraw &lt;- lhs(300, rect=rect, mode=mode, shape=shape)\npar(mfrow=c(1,3))\nfor(i in 1:3) hist(Udraw[,i], breaks=15,xlab=names(X)[i]) \n\n# build sens.p with the 'sens' function.\nsens.p &lt;- suppressWarnings(sens(X=X,Z=Z,nn.lhs=300, model=NULL,\n               ngrid=100, rect=rect, shape=shape, mode=mode))\n\n# Use predict.tgp to quickly analyze with respect to this new\n# uncertainty distribution without re-running the MCMC, then\n# plot the results.\ns.new &lt;- predict(s, BTE=c(1,1000,1), sens.p=sens.p, verb=1) \nplot(s.new, layout=\"sens\", ylab=\"Ozone\", main=\"main effects\")<\/pre>\n<h3>Results<\/h3>\n<pre><\/pre>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td><a href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_001_large.png\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_001_medium.png\" \/><\/a><a href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_002_large.png\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_002_medium.png\" \/><\/a><a href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_003_large.png\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_003_medium.png\" \/><\/a><a href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_004_large.png\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_004_medium.png\" \/><\/a><a href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_005_large.png\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/tgp\/sens.Rd_005_medium.png\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>sens R Documentation Monte Carlo Bayesian Sensitivity Analysis Description Fully Bayesian Monte Carlo sensitivity analysis scheme, based upon any of the regression models contained in&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-416","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=416"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}