# Computing Sobol sensitivity indices using existing input/output data

**URL:** <https://uqworld.org/t/computing-sobol-sensitivity-indices-using-existing-input-output-data/327>\
**Category:** Community Q&A and How To\
**Tags:** sensitivity, sobol, metamodeling\
**Created:** [December 6, 2019, 9:22pm UTC](https://uqworld.org/t/computing-sobol-sensitivity-indices-using-existing-input-output-data/327 "2019-12-06T21:22:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bsudret](https://uqworld.org/user_avatar/uqworld.org/bsudret/32/224_2.png) [@bsudret](https://uqworld.org/u/bsudret)\
**Post date:** [December 7, 2019, 4:44pm UTC](https://uqworld.org/t/computing-sobol-sensitivity-indices-using-existing-input-output-data/327/2 "2019-12-07T16:44:25Z")

</div>

Dear Gullnaz

You have to construct a surrogate model of your finite element model from your runs first. In order to do sensitivity analysis afterwards, a good choice is to use polynomial chaos expansions (PCE). The [Polynomial chaos expansion from existing data](https://www.uqlab.com/pce-truss-data-set) example is a good starting point.

### Polynomial chaos expansion

Following this example, you start by defining the distribution of the input parameters of the FE model (the distributions you used to sample the inputs). If you did this step with UQLab, simply reuse your UQLab input object.

Then you build a PCE as follows:

```matlab
MetaOpts.Type = 'Metamodel';
MetaOpts.MetaType = 'PCE';
MetaOpts.ExpDesign.X = <your matrix of inputs>;
MetaOpts.ExpDesign.Y = <your matrix of outputs>;
MetaOpts.Degree = 1:5;
% 
myPCE = uq_createModel(MetaOpts);

```

Your input data should be organized in a N \times M matrix, where M is the number of input parameters of your problem and N the number of runs you did. Accordingly your output data (the response of the finite element model) should be organized in a N \times Q matrix, where Q is the number of output quantities of interest (I suggest you start with Q=1 first). Make sure that the lines of the input and output correspond !

### Computation of Sobol’ indices

You can carry out sensitivity analysis using these few lines of codes (many more options can be set up, see the [documentation](http://uqftp.ethz.ch/uqlab_doc_pdf/1.3.0/UserManual_Sensitivity.pdf) if needed):

```matlab
SobolOpts.Type = 'Sensitivity';
SobolOpts.Method = 'Sobol';
SobolOpts.Sobol.Order = 1;
mySobol = uq_createAnalysis(SobolOpts);
uq_print(mySobol) % print the Sobol' indices
uq_display(mySobol) % display the Sobol' indices

```

Note that if you have uniform distributions for your input variables (_only in this case_), you can get the same results using the online [Sobol’ index calculator](https://www.sobolindices.com/), which exactly follows the procedure described above.

I hope it will be helpful!  
Best regards  
Bruno

---

_[View the full topic](https://uqworld.org/t/computing-sobol-sensitivity-indices-using-existing-input-output-data/327)._
