Skip to contents

gsa(f, method, p_range, samples = n) evaluates the model f on a design over the parameter ranges and returns the sensitivity measures of method (see gsa_methods). p_range is a list of c(lower, upper) pairs, or of distributions for eFAST() and DGSM(), a SklarDist() for Shapley(). f takes a parameter vector and returns a number, a vector or an ODE solution; with batch = TRUE it takes a matrix with one parameter set per column and returns one value (or one column) per set.

Usage

gsa(
  f,
  method,
  p_range = NULL,
  B = NULL,
  samples = NULL,
  batch = FALSE,
  rng = NULL,
  Ei_estimator = "Jansen1999",
  num_params = NULL,
  ...
)

Arguments

f

The model, or the sample matrix X.

method

A method from gsa_methods, or the outputs Y.

p_range

Parameter ranges or distributions, the design matrix A, or the method in the gsa(X, Y, method) form.

B

Second design matrix of the Sobol method.

samples

Number of samples.

batch

Whether f evaluates a matrix of parameter sets.

rng

NULL for R's generator, or a function of n returning n uniform numbers on [0, 1).

Ei_estimator

Estimator of the total effects of Sobol(): "Jansen1999", "Homma1996", "Sobol2007" or "Janon2014".

num_params

Number of parameters (fractional factorial and RBD-FAST).

...

Unused.

Value

A result list whose fields follow the Julia result types, for example S1, ST and S2 for Sobol, means, means_star and variances for Morris.

Details

The samples of the range forms are randomized quasi Monte Carlo (Owen scrambled Sobol points), except for EASI(), whose bias correction assumes independent uniform samples and which draws those. Sobol() evaluates nboot independent scrambled designs of dimension 2 d, whose first and last d rows are the A and B matrices, so the estimators are applied to independent pairs of points, repeated runs are independent replicates, and the intervals with nboot > 1 come from independent replicates. GlobalSensitivity.jl uses the unscrambled sequence; pass matrices from generate_design_matrices() with NoRand() to gsa(f, Sobol(), A, B) for its deterministic design.

Other forms, as in GlobalSensitivity.jl:

  • gsa(f, Sobol(), A, B) with design matrices A and B (one set per column), for example from generate_design_matrices();

  • gsa(X, Y, method) for RegressionGSA(), DeltaMoment() and EASI() on samples X (d x n) and outputs Y;

  • gsa(f, FractionalFactorial(), num_params = k, p_range = levels) and gsa(f, RBDFAST(), num_params = k, samples = n).

Examples

ishi <- function(x) sin(x[1]) + 7 * sin(x[2])^2 + 0.1 * x[3]^4 * sin(x[1])
rg <- rep(list(c(-pi, pi)), 3)
set.seed(1)
res <- gsa(ishi, Sobol(), rg, samples = 1000)
res$S1
#> [1]  0.29015747  0.44532681 -0.01090405
set.seed(1)
gsa(ishi, eFAST(), rg, samples = 500)$S1
#>           [,1]      [,2]        [,3]
#> [1,] 0.3081658 0.4420054 1.08737e-29