Getting started

Assume we have a simple model, fsens, which depends on two parameters, a and b and produces two outputs, target1 and target2.

fsens = (a,b) -> (;target1 = 10a + b -1, target2 = a + b -0.5)

Our knowledge about reasonable model parameters is encoded by a prior probability distribution. We can specify those by the kind of distribution, its mode and an upper quantile.

using SubglobalSensitivityAnalysis, Distributions
install_R_dependencies(["sensitivity"])

paramsModeUpperRows = [
    (:a, LogNormal, 0.2 , 0.5),
    (:b, LogitNormal, 0.7 , 0.9),
]
┌ Warning: RCall.jl: Loading required namespace: sensitivity
Registered S3 method overwritten by 'sensitivity':
  method    from
  print.src dplyr
@ RCall ~/.julia/packages/RCall/YrsKg/src/io.jl:172

The output DataFrame reports

  • the estimated index and confidence bounds (column value, cflower, cfupper)
  • for each of the parameter/index_type/output combinations

We can provide this directly to estimate_subglobal_sobol_indices below, or we estimate/specify distribution parameters directly in a DataFrame with column :dist.

df_dist = fit_distributions(paramsModeUpperRows)
2×5 DataFrame
RowpardTypemodeupperdist
SymbolUnionAllFloat64Float64Distribu…
1aLogNormal0.20.5Distributions.LogNormal{Float64}(μ=-1.60944, σ=0.467504)
2bLogitNormal0.70.9Distributions.LogitNormal{Float64}(μ=0.847298, σ=0.688751)

While these distributions are reasonable for each parameter, there are probably parameter combinations that produce unreasonable results. Hence, we want to restrict our analysis to a parameter space around a central parameter vector, p0.

p0 = Dict(:a => 0.34, :b => 0.6)

By default a range around p0 is created that covers 20% of the cumulative probability range, i.e a span of 0.2.

Example block output

For this range 20% of the area under the probability density function is covered.

Example block output

The design matrix for the sensitivity analysis is constructed in the cumulative densities and transformed to parameter values. For each of the parameter vectors of the design matrix an output is computed. Now the Sobol indices and their confidence ranges can be computed for this output.

All this encapsulated by function estimate_subglobal_sobol_indices.

# note, for real analysis use a larger sample size
df_sobol = estimate_subglobal_sobol_indices(fsens, df_dist, p0; n_sample = 50)
df_sobol
8×6 DataFrame
Rowparindexvaluecf_lowercf_uppertarget
SymbolSymbolFloat64Float64Float64Symbol
1afirst_order0.9952910.9416481.04893target1
2bfirst_order-0.0166506-0.2793130.246012target1
3atotal1.014340.7480231.28066target1
4btotal0.00355108-0.04587290.0529751target1
5afirst_order0.6490360.4851090.812963target2
6bfirst_order0.2591240.09522840.42302target2
7atotal0.7198840.5018370.937931target2
8btotal0.2509960.1646510.337341target2

The resulting DataFrame reports:

  • the estimated Sobol indices and their confidence bounds (columns value, cflower, cfupper)
  • for all the combinations of parameter, which index, and output (columns par, index, target)