# Why does the Sobol Sensitivity (S1) so large in my model

**URL:** <https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507>\
**Category:** General Usage\
**Tags:** question, package, globalsensitivityjl\
**Created:** [March 30, 2025, 12:08pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507 "2025-03-30T12:08:49Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 30, 2025, 12:08pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/1 "2025-03-30T12:08:49Z")

</div>

I am running a model in Julia with 42 parameters (they are somehow inner-correlated with each other) and 6 outputs, and trying to use the function `gsa` from the package `GlobalSensitivity.jl` to diagnose the ST and S1 sensitivity. However, the ST seems to be ok, but there are a lot of `f16` values in S1 values…I am using `N=10000` for the sample size, and

```julia
A, B = QuasiMonteCarlo.generate_design_matrices(samples, lb, ub, sampler)

```

to sample design matrix for GSA…here attached the matrix of S1. I am wondering why there are so many `f16` values? for example, the 13th parameter, and last two parameters…

[![enter image description here](https://global.discourse-cdn.com/julialang/original/3X/a/3/a3c64f596a422669fa3e303627ac337dfdb8cd84.png)](https://i.sstatic.net/Cb47Ggtr.png)

---

<div class="post-metadata">

**Author:** ![ConnectedSystems](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/connectedsystems/32/16815_2.png) [@ConnectedSystems](https://discourse.julialang.org/u/ConnectedSystems)\
**Post date:** [March 31, 2025, 2:37am UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/2 "2025-03-31T02:37:41Z")

</div>

Could you show a full example? The results look strange to me.

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 31, 2025, 11:20am UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/3 "2025-03-31T11:20:45Z")

</div>

what do you mean by full example? the code to calculate sensitivity is embeded in other subroutines…here is the function to do it:

```julia
function globalSensitivity(cost_function, method_options, p_bounds, ::GlobalSensitivitySobolDM; batch=true)
    sampler = getproperty(SindbadOptimization.GlobalSensitivity, Symbol(method_options.sampler))(; method_options.sampler_options...);
    samples = method_options.samples;
    lb = first.(p_bounds);
    ub = last.(p_bounds);
    @debug samples
    A, B = QuasiMonteCarlo.generate_design_matrices(samples, lb, ub, sampler);
    @debug size(A)
    @debug method_options
    results = gsa(cost_function, Sobol(; method_options.method_options...), A, B; method_options..., batch=batch);
    return results
end

```

`results` is the `out_sensitivity.sensitivity` in the snapshot…in this function call, I set `N=10000`, and using cost function which returns loss as a matrix which has size of `(num of outputs, num of evaluations)=(6, 10000*(42+2))`.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 31, 2025, 11:47am UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/4 "2025-03-31T11:47:00Z")

</div>

It’s just one row. Possibly you have a bunch of zeros and something else? We would need a way to run the model to really diagnose it, but indeed that one row is odd.

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 31, 2025, 12:18pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/5 "2025-03-31T12:18:24Z")

</div>

no? the f12/f16 values happen in the 13th row, and also last two rows…

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 31, 2025, 12:19pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/6 "2025-03-31T12:19:41Z")

</div>

it’s quite hard to share the model here…but could you please let me know how to really diagnose it? thanks! We tried to narrow down the parameters from 42 to only 10 parameters (10 parameters for one small submodel within this big model), then everything is fine…but for these 42 parameters, things are weird…

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 31, 2025, 12:21pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/7 "2025-03-31T12:21:26Z")

</div>

If you change to higher precision does it go away? Are the values of that output really large?

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 31, 2025, 12:58pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/8 "2025-03-31T12:58:39Z")

</div>

what do you mean “higher precision”? you mean increase the number of samples?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 31, 2025, 1:10pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/9 "2025-03-31T13:10:04Z")

</div>

Float64, BigFloat

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 31, 2025, 3:29pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/10 "2025-03-31T15:29:25Z")

</div>

how to change it? from the model yes there is an option to tune the output type…not sure whether there is similar option in `gsa` function…

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 31, 2025, 4:22pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/11 "2025-03-31T16:22:13Z")

</div>

It uses the precision matching your call/outputs

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [March 31, 2025, 4:31pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/12 "2025-03-31T16:31:56Z")

</div>

thanks, let me try it…

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [April 1, 2025, 7:53am UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/13 "2025-04-01T07:53:08Z")

</div>

Thanks for your suggestion…I tuned it from Float32 to Float64. However, the result is pretty similar…

 ![Screenshot 2025-04-01 at 09.50.25](https://global.discourse-cdn.com/julialang/original/3X/7/6/760048fb4bae65d8611719f9ba6a2746acdc78be.png)

However, I noticed that the S2 is very big…there are other parameters (other than the 13th and last two parameters) which show big S2 values…for example the 3rd and 4th parameters in last two columns (in S2 matrix…)

 ![Screenshot 2025-04-01 at 09.52.37](https://global.discourse-cdn.com/julialang/original/3X/9/7/974a1373fe283cb938b5d072b5c2c766f25104a7.png)

---

<div class="post-metadata">

**Author:** ![xztt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xztt/32/33843_2.png) [@xztt](https://discourse.julialang.org/u/xztt)\
**Post date:** [April 1, 2025, 10:11am UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/14 "2025-04-01T10:11:50Z")

</div>

Have you tried to look at the standard error estimates for the indices? I have seen situations like this before which arise due to a highly non-linear model and a lack of convergence in the indices.

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [April 1, 2025, 12:54pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/15 "2025-04-01T12:54:15Z")

</div>

Thanks for your reply! But how to look at the standard error estimates for the indices? you mean the confidential interval? or anything else?

---

<div class="post-metadata">

**Author:** ![xztt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xztt/32/33843_2.png) [@xztt](https://discourse.julialang.org/u/xztt)\
**Post date:** [April 1, 2025, 2:05pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/16 "2025-04-01T14:05:38Z")

</div>

if you increase the nboot keyword to around 2000. You can then look at the conf`idence intervals with res.S1\_Conf\_Int

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [April 1, 2025, 4:21pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/17 "2025-04-01T16:21:35Z")

</div>

thanks for your suggestion! With nboot=2000, the S1\_Conf\_Int is

 ![Screenshot 2025-04-01 at 18.21.09](https://global.discourse-cdn.com/julialang/original/3X/9/b/9beac67b785dc65284dbb0e91b99c7690eb8730a.png)  
It seems the error is large…

---

<div class="post-metadata">

**Author:** ![Xu\_Shan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xu_shan/32/214900_2.png) [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Post date:** [April 2, 2025, 8:59am UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/18 "2025-04-02T08:59:55Z")

</div>

Given the large error indicated by confidential interval, I guess the way to solve it to increase the number of sample? or do you have other solutions…thanks!

---

<div class="post-metadata">

**Author:** ![DanielePessina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielepessina/32/215157_2.png) [@DanielePessina](https://discourse.julialang.org/u/DanielePessina)\
**Post date:** [April 2, 2025, 12:12pm UTC](https://discourse.julialang.org/t/why-does-the-sobol-sensitivity-s1-so-large-in-my-model/127507/19 "2025-04-02T12:12:44Z")

</div>

With sensitivity indices, negative values indicate poor convergence of the SA, common with many parameters, outputs and big non linear models. The few ways to address this (to my knowledge) are:

- Increasing number of samples
- Changing SA method to one that only returns 1st and total order indices (if you’re ok without 2nd Order, these methods generally take fewer samples)
- Training a surrogate model that will make the generation of samples quicker
