Title: | Computation of Variance-Based Sensitivity Indices |
---|---|
Description: | It allows to rapidly compute, bootstrap and plot up to fourth-order Sobol'-based sensitivity indices using several state-of-the-art first and total-order estimators. Sobol' indices can be computed either for models that yield a scalar as a model output or for systems of differential equations. The package also provides a suit of benchmark tests functions and several options to obtain publication-ready figures of the model output uncertainty and sensitivity-related analysis. An overview of the package can be found in Puy et al. (2022) <doi:10.18637/jss.v102.i05>. |
Authors: | Arnald Puy [aut, cre] |
Maintainer: | Arnald Puy <[email protected]> |
License: | GPL-3 |
Version: | 1.1.5 |
Built: | 2025-02-15 04:56:21 UTC |
Source: | https://github.com/arnaldpuy/sensobol |
It allows to rapidly compute, bootstrap and plot up to third-order Sobol'-based sensitivity indices using several state-of-the-art first and total-order estimators. Sobol' indices can be computed either for models that yield a scalar as a model output or for systems of differential equations. The package also provides a suit of benchmark tests functions and several options to obtain publication-ready figures of the model output uncertainty and sensitivity-related analysis.
A comprehensive empirical study of several total-order estimators included in sensobol can be found in Puy et al. (2021).
Arnald Puy ([email protected])
Maintainer: Arnald Puy ([email protected])
Puy A, Becker W, Lo Piano S, Saltelli A (2021). “A Comprehensive Comparison of Total-Order Estimators for Global Sensitivity Analysis.” International Journal for Uncertainty Quantification. doi:10.1615/Int.J.UncertaintyQuantification.2021038133.
It implements the Bratley and Fox (1988) function.
bratley1988_Fun(X)
bratley1988_Fun(X)
X |
A data frame or numeric matrix where each column is a model input and each row a sample point. |
The function requires model inputs and reads as follows:
where .
A numeric vector with the model output.
# Define settings (test with k = 10) N <- 100; params <- paste("X", 1:10, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Bratley and Fox (1988) function Y <- bratley1988_Fun(mat)
# Define settings (test with k = 10) N <- 100; params <- paste("X", 1:10, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Bratley and Fox (1988) function Y <- bratley1988_Fun(mat)
It implements the Bratley et al. (1992) function.
bratley1992_Fun(X)
bratley1992_Fun(X)
X |
A data frame or numeric matrix where each column is a model input and each row a sample point. |
The function requires model inputs and reads as:
where .
A numeric vector with the model output.
Bratley P, Fox BL, Niederreiter H (1992). “Implementation and tests of low-discrepancy sequences.” ACM Transactions on Modeling and Computer Simulation (TOMACS), 2(3), 195–213.
# Define settings (test with k = 10) N <- 100; params <- paste("X", 1:10, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Bratley et al. (1992) function Y <- bratley1992_Fun(mat)
# Define settings (test with k = 10) N <- 100; params <- paste("X", 1:10, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Bratley et al. (1992) function Y <- bratley1992_Fun(mat)
It allows to use the S-ersatz discrepancy measure by Puy et al. (2024) as a sensitivity measure.
discrepancy_ersatz(mat, Y, params)
discrepancy_ersatz(mat, Y, params)
mat |
A numeric matrix created with |
Y |
A numeric vector with the model output obtained from the matrix created with
|
params |
A character vector with the name of the model inputs. |
It is recommended to define mat
using a power of 2 as a sample size.
A data.table
object.
Puy A, Roy PT, Saltelli A (2024). “Discrepancy measures for global sensitivity analysis.” Technometrics. doi:10.1080/00401706.2024.2304341.
# Define settings N <- 2^9; params <- paste("X", 1:8, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params, matrices = "A") # Compute the Sobol' G function Y <- sobol_Fun(mat) # Compute the S-ersatz discrepancy values ind <- discrepancy_ersatz(mat = mat, Y = Y, params = params)
# Define settings N <- 2^9; params <- paste("X", 1:8, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params, matrices = "A") # Compute the Sobol' G function Y <- sobol_Fun(mat) # Compute the S-ersatz discrepancy values ind <- discrepancy_ersatz(mat = mat, Y = Y, params = params)
It implements the Ishigami and Homma (1990) function.
ishigami_Fun(X)
ishigami_Fun(X)
X |
A data frame or numeric matrix where each column is a model input and each row a sample point. |
The function requires 3 model inputs and reads as
where ,
and
. The
transformation of the distribution of the model inputs from
to
) is conducted internally.
A numeric vector with the model output.
Ishigami T, Homma T (1990). “An importance quantification technique in uncertainty analysis for computer models.” Proceedings. First International Symposium on Uncertainty Modeling and Analysis, 12, 398–403.
# Define settings N <- 100; params <- paste("X", 1:3, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat)
# Define settings N <- 100; params <- paste("X", 1:3, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat)
The function loads R packages. If the packages are not already in the local system, the function also downloads, installs and loads them.
load_packages(x)
load_packages(x)
x |
A character vector with the name of the packages to load. |
# Load packages: ## Not run: load_packages(c("tidyverse", "data.table"))
# Load packages: ## Not run: load_packages(c("tidyverse", "data.table"))
Random metafunction based on Becker (2020)'s metafunction.
metafunction(data, k_2 = 0.5, k_3 = 0.2, epsilon = NULL)
metafunction(data, k_2 = 0.5, k_3 = 0.2, epsilon = NULL)
data |
A numeric matrix where each column is a model input and each row a sampling point. |
k_2 |
Numeric value indicating the fraction of active pairwise interactions (between 0 and 1).
Default is |
k_3 |
Numeric value indicating the fraction of active three-wise interactions
(between 0 and 1). Default is |
epsilon |
Integer value. It fixes the seed for the random number generator.
The default is |
The metafunction randomly combines the following functions in a metafunction of dimension :
(cubic).
(discontinuous).
(exponential).
(inverse).
(linear)
(no effect).
(non-monotonic).
(periodic).
(quadratic).
(trigonometric).
It is constructed as follows:
where is the model dimensionality,
is a
-length vector formed by randomly
sampling with replacement the ten functions mentioned above,
and
are two matrices specifying the
number of pairwise and three-wise interactions given the model dimensionality,
and
are three
vectors of length
generated by sampling from a mixture of two normal distributions
.
See Puy et al. (2020) and Becker (2020) for a full
mathematical description of the metafunction approach.
A numeric vector with the function output.
Becker W (2020).
“Metafunctions for benchmarking in sensitivity analysis.”
Reliability Engineering and System Safety, 204, 107189.
doi:10.1016/j.ress.2020.107189.
Puy A, Becker W, Piano SL, Saltelli A (2020).
“The battle of total-order sensitivity estimators.”
arXiv.
2009.01147, https://arxiv.org/abs/2009.01147.
# Define settings (number of model inputs = 86) N <- 100; params <- paste("X", 1:86, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute metafunction Y <- metafunction(mat)
# Define settings (number of model inputs = 86) N <- 100; params <- paste("X", 1:86, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute metafunction Y <- metafunction(mat)
It implements the Oakley and O'Hagan (2004) function.
oakley_Fun(X)
oakley_Fun(X)
X |
A data frame or numeric matrix where each column is a model input and each row a sample point. |
The function requires 15 model inputs and reads as
where ,
, and values
for
and
are defined by Oakley and O'Hagan (2004). The
transformation of the distribution of the model inputs from
to
) is conducted internally.
A numeric vector with the model output.
Oakley JE, O'Hagan A (2004). “Probabilistic sensitivity analysis of complex models: a Bayesian approach.” Journal of the Royal Statistical Society B, 66(3), 751–769. doi:10.1111/j.1467-9868.2004.05304.x.
# Define settings N <- 100; params <- paste("X", 1:15, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Oakley and O'Hagan (2004) function Y <- oakley_Fun(mat)
# Define settings N <- 100; params <- paste("X", 1:15, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Oakley and O'Hagan (2004) function Y <- oakley_Fun(mat)
It plots all pairwise combinations of model inputs with the colour proportional the model output value.
plot_multiscatter(data, N, Y, params, smpl = NULL)
plot_multiscatter(data, N, Y, params, smpl = NULL)
data |
The matrix created with |
N |
Positive integer, the initial sample size of the base sample matrix created with |
Y |
A numeric vector with the model output obtained from the matrix created with
|
params |
Character vector with the name of the model inputs. |
smpl |
The number of simulations to plot. The default is NULL. |
A ggplot2
object.
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Plot scatterplot matrix plot_multiscatter(data = mat, N = N, Y = Y, params = params)
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Plot scatterplot matrix plot_multiscatter(data = mat, N = N, Y = Y, params = params)
It creates scatter plots of the model output against the model inputs.
plot_scatter(data, N, Y, params, method = "point", size = 0.7, alpha = 0.2)
plot_scatter(data, N, Y, params, method = "point", size = 0.7, alpha = 0.2)
data |
The matrix created with |
N |
Positive integer, the initial sample size of the base sample matrix created with |
Y |
A numeric vector with the model output obtained from the matrix created with
|
params |
Character vector with the name of the model inputs. |
method |
The type of plot. If |
size |
Number between 0 and 1, argument of |
alpha |
Number between 0 and 1, transparency scale of |
A ggplot2
object.
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Plot scatter plot_scatter(data = mat, Y = Y, N = N, params = params)
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Plot scatter plot_scatter(data = mat, Y = Y, N = N, params = params)
It creates an histogram with the model output distribution.
plot_uncertainty(Y, N = NULL)
plot_uncertainty(Y, N = NULL)
Y |
A numeric vector with the model output obtained from the matrix created with
|
N |
Positive integer, the initial sample size of the base sample matrix created with |
A ggplot2
object.
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Plot uncertainty plot_uncertainty(Y = Y, N = N)
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Plot uncertainty plot_uncertainty(Y = Y, N = N)
It plots first, total, second, third and fourth-order Sobol' indices.
## S3 method for class 'sensobol' plot(x, order = "first", dummy = NULL, ...)
## S3 method for class 'sensobol' plot(x, order = "first", dummy = NULL, ...)
x |
The output of |
order |
If |
dummy |
The output of |
... |
Other graphical parameters to plot. |
A ggplot
object.
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Compute and bootstrap Sobol' indices ind <- sobol_indices(Y = Y, N = N, params = params, boot = TRUE, R = R) # Plot Sobol' indices plot(ind)
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Compute and bootstrap Sobol' indices ind <- sobol_indices(Y = Y, N = N, params = params, boot = TRUE, R = R) # Plot Sobol' indices plot(ind)
sobol_indices
function.Display the results obtained with the sobol_indices
function.
## S3 method for class 'sensobol' print(x, ...)
## S3 method for class 'sensobol' print(x, ...)
x |
A |
... |
Further arguments passed to or from other methods. |
The function print.sensobol
informs on the first and total-order
estimators used in the computations, the total number of model runs and
the sum of first-order index. It also plots the estimated results.
vars_to
function.Display the results obtained with the vars_to
function.
## S3 method for class 'vars' print(x, ...)
## S3 method for class 'vars' print(x, ...)
x |
A |
... |
Further arguments passed to or from other methods. |
The function print.vars
informs on the number of star centers,
the value of h used and the total number of model runs.. It also plots
the VARS-TO indices.
It checks the convergence of Sobol' indices on different sub-samples of the model output-.
sobol_convergence( matrices, Y, N, sub.sample, params, first, total, order = order, seed = 666, plot.order, ... )
sobol_convergence( matrices, Y, N, sub.sample, params, first, total, order = order, seed = 666, plot.order, ... )
matrices |
Character vector with the required matrices. The default is |
Y |
Numeric vector with the model output obtained from the matrix created with
|
N |
Positive integer, the initial sample size of the base sample matrix created with |
sub.sample |
Numeric vector with the sub-samples of the model output at which to check convergence. |
params |
Character vector with the name of the model inputs. |
first |
Estimator to compute first-order indices. Check options in |
total |
Estimator to compute total-order indices. Check options in |
order |
Whether to plot convergence for "second" or "third" order indices. |
seed |
Whether to compute "first", "second", or "third" -order Sobol' indices. Default
is |
plot.order |
Whether to plot convergence for "second" or "third"-order indices. |
... |
Further arguments in |
A list with the results and the plots
# Define settings matrices <- c("A", "B", "AB") params <- paste("X", 1:3, sep = "") N <- 2^10 first <- "saltelli" total <- "jansen" order <- "second" # Create sample matrix mat <- sobol_matrices(N = N, params = params, order = order) # Compute Ishigami function Y <- ishigami_Fun(mat) # Check convergence at specific sample sizes sub.sample <- seq(100, N, 500) # Define sub-samples sobol_convergence(matrices = matrices, Y = Y, N = N, sub.sample = sub.sample, params = params, first = first, total = total, order = order, plot.order = order)
# Define settings matrices <- c("A", "B", "AB") params <- paste("X", 1:3, sep = "") N <- 2^10 first <- "saltelli" total <- "jansen" order <- "second" # Create sample matrix mat <- sobol_matrices(N = N, params = params, order = order) # Compute Ishigami function Y <- ishigami_Fun(mat) # Check convergence at specific sample sizes sub.sample <- seq(100, N, 500) # Define sub-samples sobol_convergence(matrices = matrices, Y = Y, N = N, sub.sample = sub.sample, params = params, first = first, total = total, order = order, plot.order = order)
This function computes first and total-order Sobol' indices for a dummy parameter following the formulae shown in Khorashadi Zadeh et al. (2017).
sobol_dummy( Y, N, params, boot = FALSE, R = NULL, parallel = "no", ncpus = 1, conf = 0.95, type = "norm" )
sobol_dummy( Y, N, params, boot = FALSE, R = NULL, parallel = "no", ncpus = 1, conf = 0.95, type = "norm" )
Y |
A numeric vector with the model output obtained from the matrix created with
|
N |
Positive integer, the initial sample size of the base sample matrix created with |
params |
A character vector with the name of the model inputs. |
boot |
Logical. If TRUE, the function bootstraps the Sobol' indices. If FALSE, it provides point
estimates. Default is |
R |
Positive integer, number of bootstrap replicas. |
parallel |
The type of parallel operation to be used (if any).
If missing, the default is taken from the option "boot.parallel"
(and if that is not set, "no"). For more information, check the
|
ncpus |
Positive integer: number of processes to be used in parallel operation:
typically one would chose this to the number of available CPUs.
Check the |
conf |
Confidence intervals, number between 0 and 1. Default is |
type |
Method to compute the confidence intervals. Default is |
A data.table
object.
Khorashadi Zadeh F, Nossent J, Sarrazin F, Pianosi F, van Griensven A, Wagener T, Bauwens W (2017). “Comparison of variance-based and moment-independent global sensitivity analysis approaches by application to the SWAT model.” Environmental Modelling and Software, 91, 210–222. doi:10.1016/j.envsoft.2017.02.001.
# Define settings N <- 100; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Compute and bootstrap Sobol' indices for dummy parameter ind.dummy <- sobol_dummy(Y = Y, N = N, params = params, boot = TRUE, R = R)
# Define settings N <- 100; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Compute and bootstrap Sobol' indices for dummy parameter ind.dummy <- sobol_dummy(Y = Y, N = N, params = params, boot = TRUE, R = R)
It implements the Sobol' (1998) G function.
sobol_Fun(X)
sobol_Fun(X)
X |
A data frame or numeric matrix. |
The function requires eight model inputs and reads as
where ,
and
.
A numeric vector with the model output.
Sobol' IM (1998). “On quasi-Monte Carlo integrations.” Mathematics and Computers in Simulation, 47(2-5), 103–112. doi:10.1016/S0378-4754(98)00096-2.
# Define settings N <- 100; params <- paste("X", 1:8, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Sobol' G Y <- sobol_Fun(mat)
# Define settings N <- 100; params <- paste("X", 1:8, sep = "") # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Sobol' G Y <- sobol_Fun(mat)
It allows to compute Sobol' indices up to the fourth-order using state-of-the-art estimators.
sobol_indices( matrices = c("A", "B", "AB"), Y, N, params, first = "saltelli", total = "jansen", order = "first", boot = FALSE, R = NULL, parallel = "no", ncpus = 1, conf = 0.95, type = "norm" )
sobol_indices( matrices = c("A", "B", "AB"), Y, N, params, first = "saltelli", total = "jansen", order = "first", boot = FALSE, R = NULL, parallel = "no", ncpus = 1, conf = 0.95, type = "norm" )
matrices |
Character vector with the required matrices. The default is |
Y |
Numeric vector with the model output obtained from the matrix created with
|
N |
Positive integer, the initial sample size of the base sample matrix created with |
params |
Character vector with the name of the model inputs. |
first |
Estimator to compute first-order indices. Options are:
|
total |
Estimator to compute total-order indices. Options are:
|
order |
Whether to compute "first", "second", "third" or fourth-order Sobol' indices. Default
is |
boot |
Logical. If TRUE, the function bootstraps the Sobol' indices. If FALSE, it provides point
estimates. Default is |
R |
Positive integer, number of bootstrap replicas. Default is NULL. |
parallel |
The type of parallel operation to be used (if any).
If missing, the default is taken from the option "boot.parallel"
(and if that is not set, "no"). For more information, check the
|
ncpus |
Positive integer: number of processes to be used in parallel operation:
typically one would chose this to the number of available CPUs.
Check the |
conf |
Confidence interval if |
type |
Method to compute the confidence interval if |
Any first and total-order estimator can be combined with the appropriate sampling design. Check Table 3 of the vignette for a summary of all possible combinations, and Tables 1 and 2 for a mathematical description of the estimators. If the analyst mismatches estimators and sampling designs, the function will generate an error and urge to redefine the sample matrices or the estimators.
For all estimators except Azzini et al. (2020)'s and Janon et al. (2014)'s,
sobol_indices()
calculates the sample mean as
where is the row dimension of the base sample matrix, and the unconditional sample variance as
where (
) indicates the model output
obtained after running the model
in the
-th row of the
(
) matrix.
For the Azzini estimator,
and for the Janon estimator,
where (
) is the model output obtained after running the model
in
the
-th row of an
(
) matrix, where all columns come from
(
)
except the
-th, which comes from
(
).
A sensobol
object.
Azzini I, Mara T, Rosati R (2020).
“Monte Carlo estimators of first-and total-orders Sobol' indices.”
arXiv.
2006.08232, https://arxiv.org/abs/2006.08232.
Glen G, Isaacs K (2012).
“Estimating Sobol sensitivity indices using correlations.”
Environmental Modelling and Software, 37, 157–166.
doi:10.1016/j.envsoft.2012.03.014.
Homma T, Saltelli A (1996).
“Importance measures in global sensitivity analysis of nonlinear models.”
Reliability Engineering and System Safety, 52, 1–17.
doi:10.1016/0951-8320(96)00002-6.
Janon A, Klein T, Lagnoux A, Nodet M, Prieur C (2014).
“Asymptotic normality and efficiency of two Sobol index estimators.”
ESAIM: Probability and Statistics, 18(3), 342–364.
doi:10.1051/ps/2013040.
Jansen M (1999).
“Analysis of variance designs for model output.”
Computer Physics Communications, 117(1), 35–43.
doi:10.1016/S0010-4655(98)00154-4.
Saltelli A, Annoni P, Azzini I, Campolongo F, Ratto M, Tarantola S (2010).
“Variance based sensitivity analysis of model output. Design and estimator for the total sensitivity index.”
Computer Physics Communications, 181(2), 259–270.
doi:10.1016/j.cpc.2009.09.018.
Saltelli A, Ratto M, Andres T, Campolongo F, Cariboni J, Gatelli D, Saisana M, Tarantola S (2008).
Global Sensitivity Analysis. The Primer.
John Wiley and Sons, Ltd, Chichester, UK.
doi:10.1002/9780470725184.
Sobol' IM (1993).
“Sensitivity analysis for nonlinear mathematical models.”
Mathematical Modeling and Computational Experiment, 1(4), 407–414.
Sobol' IM (2001).
“Global sensitivity indices for nonlinear mathematical models and their Monte Carlo estimates.”
Mathematics and Computers in Simulation, 55(1-3), 271–280.
doi:10.1016/S0378-4754(00)00270-6.
Check the function boot
for further details on the bootstrapping
with regards to the methods available for the computation of confidence intervals in the type
argument.
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Compute and bootstrap Sobol' indices ind <- sobol_indices(Y = Y, N = N, params = params, boot = TRUE, R = R)
# Define settings N <- 1000; params <- paste("X", 1:3, sep = ""); R <- 10 # Create sample matrix mat <- sobol_matrices(N = N, params = params) # Compute Ishigami function Y <- ishigami_Fun(mat) # Compute and bootstrap Sobol' indices ind <- sobol_indices(Y = Y, N = N, params = params, boot = TRUE, R = R)
It creates the sample matrices to compute Sobol' first and total-order indices. If needed, it also creates the sample matrices required to compute second, third and fourth-order indices.
sobol_matrices( matrices = c("A", "B", "AB"), N, params, order = "first", type = "QRN", ... )
sobol_matrices( matrices = c("A", "B", "AB"), N, params, order = "first", type = "QRN", ... )
matrices |
Character vector with the required matrices. The default
is |
N |
Positive integer, initial sample size of the base sample matrix. |
params |
Character vector with the name of the model inputs. |
order |
One of "first", "second", "third" or "fourth" to create a matrix to
compute first, second, third or up to fourth-order Sobol' indices. The default is
|
type |
Approach to construct the sample matrix. Options are:
|
... |
Further arguments in |
Before calling sobol_matrices
, the user must decide which estimators
will be used to compute first and total-order indices, for this option conditions
the design of the sample matrix and therefore the argument matrices
.
See Table 3 in the vignette for further details on the specific sampling designs required by
the estimators.
The user can select one of the following sampling designs:
,
,
.
,
,
.
,
,
,
.
If order = "first"
, the function creates an matrix according to the approach defined by
type
, where the leftmost and the rightmost columns are respectively allocated
to the
and the
matrix. Depending on the sampling design, it
also creates
(
) matrices, where all
columns come from
(
) except the
-th, which comes from
(
). All matrices are returned row-binded.
If order = "second"
, extra
(
) matrices are created, where all columns come from
(
) except the
-th and
-th, which come from
(
). These matrices allow the computation of second-order effects, and are row-bound
to those created for first and total-order indices.
If order = "third"
, extra
(
) matrices are bound below those created
for the computation of second-order effects. In these matrices, all columns come from
(
) except the
-th, the
-th and the
-th, which come from
(
). These matrices are needed to compute third-order effects, and are row-bound below
those created for second-order effects.
The same process applies to create the matrices to compute fourth-order effects.
All columns are distributed in (0,1). If the uncertainty in some parameter(s) is better described with another distribution, the user should apply the required quantile inverse transformation to the column of interest once the sample matrix is produced.
A numeric matrix where each column is a model input distributed in (0,1) and each row a sampling point.
McKay MD, Beckman RJ, Conover WJ (1979).
“Comparison of three methods for selecting values of input variables in the analysis of output from a computer code.”
Technometrics, 21(2), 239–245.
doi:10.1080/00401706.1979.10489755.
Sobol' IM (1967).
“On the distribution of points in a cube and the approximate evaluation of integrals.”
USSR Computational Mathematics and Mathematical Physics, 7(4), 86–112.
doi:10.1016/0041-5553(67)90144-9.
# Define settings N <- 100; params <- paste("X", 1:10, sep = ""); order <- "third" # Create sample matrix using Sobol' Quasi Random Numbers. mat <- sobol_matrices(N = N, params = params, order = order) # Let's assume that the uncertainty in X3 is better described # with a normal distribution with mean 0 and standard deviation 1: mat[, 3] <- qnorm(mat[, 3], 0, 1)
# Define settings N <- 100; params <- paste("X", 1:10, sep = ""); order <- "third" # Create sample matrix using Sobol' Quasi Random Numbers. mat <- sobol_matrices(N = N, params = params, order = order) # Let's assume that the uncertainty in X3 is better described # with a normal distribution with mean 0 and standard deviation 1: mat[, 3] <- qnorm(mat[, 3], 0, 1)
deSolve
ode
.It solves a system of ordinary differential equations and extracts the model output at the selected times.
sobol_ode(d, times, timeOutput, state, func, ...)
sobol_ode(d, times, timeOutput, state, func, ...)
d |
Character vector with the name of the model inputs. |
times |
Time sequence as defined by |
timeOutput |
Numeric vector determining the time steps at which the output is wanted. |
state |
Initial values of the state variables. |
func |
An R function as defined by |
... |
Additional arguments passed to |
A matrix with the output values.
# Define the model: the Lotka-Volterra system of equations lotka_volterra_fun <- function(t, state, parameters) { with(as.list(c(state, parameters)), { dX <- r * X * (1 - X / K) - alpha * X * Y dY <- -m * Y + theta * X * Y list(c(dX, dY)) }) } # Define the settings of the sensitivity analysis N <- 2 ^ 5 # Sample size of sample matrix params <- c("r", "alpha", "m", "theta", "K", "X", "Y") # Parameters # Define the times times <- seq(5, 20, 1) # Define the times at which the output is wanted timeOutput <- c(10, 15) # Construct the sample matrix mat <- sobol_matrices(N = N, params = params) # Transform to appropriate distributions mat[, "r"] <- qunif(mat[, "r"], 0.8, 1.8) mat[, "alpha"] <- qunif(mat[, "alpha"], 0.2, 1) mat[, "m"] <- qunif(mat[, "m"], 0.6, 1) mat[, "theta"] <- qunif(mat[, "theta"], 0.05, 0.15) mat[, "K"] <- qunif(mat[, "K"], 47, 53) mat[, "X"] <- floor(mat[, "X"] * (15 - 8 + 1) + 8) mat[, "Y"] <- floor(mat[, "Y"] * (2 - 6 + 1) + 6) # Run the model y <- list() for (i in 1:nrow(mat)) { y[[i]] <- sobol_ode(d = mat[i, ], times = times, timeOutput = timeOutput, state = c(X = mat[[i, "X"]], Y = mat[[i, "Y"]]), func = lotka_volterra_fun) }
# Define the model: the Lotka-Volterra system of equations lotka_volterra_fun <- function(t, state, parameters) { with(as.list(c(state, parameters)), { dX <- r * X * (1 - X / K) - alpha * X * Y dY <- -m * Y + theta * X * Y list(c(dX, dY)) }) } # Define the settings of the sensitivity analysis N <- 2 ^ 5 # Sample size of sample matrix params <- c("r", "alpha", "m", "theta", "K", "X", "Y") # Parameters # Define the times times <- seq(5, 20, 1) # Define the times at which the output is wanted timeOutput <- c(10, 15) # Construct the sample matrix mat <- sobol_matrices(N = N, params = params) # Transform to appropriate distributions mat[, "r"] <- qunif(mat[, "r"], 0.8, 1.8) mat[, "alpha"] <- qunif(mat[, "alpha"], 0.2, 1) mat[, "m"] <- qunif(mat[, "m"], 0.6, 1) mat[, "theta"] <- qunif(mat[, "theta"], 0.05, 0.15) mat[, "K"] <- qunif(mat[, "K"], 47, 53) mat[, "X"] <- floor(mat[, "X"] * (15 - 8 + 1) + 8) mat[, "Y"] <- floor(mat[, "Y"] * (2 - 6 + 1) + 6) # Run the model y <- list() for (i in 1:nrow(mat)) { y[[i]] <- sobol_ode(d = mat[i, ], times = times, timeOutput = timeOutput, state = c(X = mat[[i, "X"]], Y = mat[[i, "Y"]]), func = lotka_volterra_fun) }
It creates the STAR-VARS matrix needed to compute VARS-TO following Razavi and Gupta (2016).
vars_matrices(star.centers, params, h = 0.1, type = "QRN", ...)
vars_matrices(star.centers, params, h = 0.1, type = "QRN", ...)
star.centers |
Positive integer, number of star centers. |
params |
Character vector with the name of the model inputs. |
h |
Distance between pairs. The user should select between 0.001, 0.002, 0.005, 0.01,
0.02, 0.05, 0.1, 0.2. Default is |
type |
Approach to construct the STAR-VARS. Options are:
|
... |
Further arguments in |
The user randomly selects points across the factor space using
either Sobol' Quasi Random Numbers (
type = "QRN"
) or random numbers (type = "R"
).
These are the star centres and their location can be denoted as
, where
.
Then, for each star centre, the function generates a cross section of equally spaced points
apart for each of the
model inputs, including and passing through the
star centre. The cross section is produced by fixing
and varying
.
Finally, for each factor all pairs of points with
values of
and so on are extracted. The total computational cost of this design is
.
A matrix where each column is a model input and each row a sampling point.
Razavi S, Gupta HV (2016).
“A new framework for comprehensive, robust, and efficient global sensitivity analysis: 2. Application.”
Water Resources Research, 52(1), 440–455.
doi:10.1002/2015WR017558, 2014WR016527.
Sobol' IM (1967).
“On the distribution of points in a cube and the approximate evaluation of integrals.”
USSR Computational Mathematics and Mathematical Physics, 7(4), 86–112.
doi:10.1016/0041-5553(67)90144-9.
# Define settings star.centers <- 10; params <- paste("X", 1:5, sep = ""); h <- 0.1 # Create STAR-VARS mat <- vars_matrices(star.centers = star.centers, params = params, h = h)
# Define settings star.centers <- 10; params <- paste("X", 1:5, sep = ""); h <- 0.1 # Create STAR-VARS mat <- vars_matrices(star.centers = star.centers, params = params, h = h)
It computes VARS-TO following Razavi and Gupta (2016).
vars_to(Y, star.centers, params, h, method = "all.step")
vars_to(Y, star.centers, params, h, method = "all.step")
Y |
A numeric vector with the model output obtained from the matrix created with
|
star.centers |
Positive integer, number of star centers. |
params |
Character vector with the name of the model inputs. |
h |
Distance between pairs. |
method |
Type of computation. If |
VARS is based on variogram analysis to characterize the spatial structure and variability
of a given model output across the input space (Razavi and Gupta 2016). Variance-
based total-order effects can be computed as by-products of the VARS framework. The total-order index
is related to the variogram and co-variogram
functions by the
following equation:
where is a vector of all
factors except
.
A data.table
with the VARS-TO indices of each parameter.
Razavi S, Gupta HV (2016). “A new framework for comprehensive, robust, and efficient global sensitivity analysis: 2. Application.” Water Resources Research, 52(1), 440–455. doi:10.1002/2015WR017558, 2014WR016527.
# Define settings star.centers <- 10; params <- paste("X", 1:3, sep = ""); h <- 0.1 # Create STAR-VARS mat <- vars_matrices(star.centers = star.centers, params = params, h = h) # Run model y <- sensobol::ishigami_Fun(mat) # Compute VARS-TO ind <- vars_to(Y = y, star.centers = star.centers, params = params, h = h) ind
# Define settings star.centers <- 10; params <- paste("X", 1:3, sep = ""); h <- 0.1 # Create STAR-VARS mat <- vars_matrices(star.centers = star.centers, params = params, h = h) # Run model y <- sensobol::ishigami_Fun(mat) # Compute VARS-TO ind <- vars_to(Y = y, star.centers = star.centers, params = params, h = h) ind