# Input Discrete Data along with

**URL:** <https://uqworld.org/t/input-discrete-data-along-with/1168>\
**Category:** Community Q&A and How To\
**Tags:** sensitivity\
**Created:** [May 7, 2021, 1:29pm UTC](https://uqworld.org/t/input-discrete-data-along-with/1168 "2021-05-07T13:29:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunny123](https://uqworld.org/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Sunny123](https://uqworld.org/u/Sunny123)\
**Post date:** [May 7, 2021, 1:29pm UTC](https://uqworld.org/t/input-discrete-data-along-with/1168/1 "2021-05-07T13:29:57Z")

</div>

How to input discrete random Variable.

I am doing Sobol sensitivity Analysis for a data set having four input Variable and one Output. Three Input Variable are continuous following a Log normal distribution. The Fourth Variable is a discrete Random Variable. following a uniform distribution. How can such input data set can be called into the uqlab.

---

<div class="post-metadata">

**Author:** ![xujia](https://uqworld.org/user_avatar/uqworld.org/xujia/32/214_2.png) [@xujia](https://uqworld.org/u/xujia)\
**Post date:** [October 1, 2021, 4:05pm UTC](https://uqworld.org/t/input-discrete-data-along-with/1168/2 "2021-10-01T16:05:22Z")

</div>

Hi @Sunny123,

Welcome to UQWorld, and thanks for creating this post.

So far, UQLab does not support discrete random variables, but we are working on it now, which will be included in a future version.

Nevertheless, if you have a computational model, you can still use the sampling-based method to calculate the Sobol’ indices (see Section 2.1.8 of the [manual](https://uqftp.ethz.ch/uqlab_doc_pdf/1.4.0/UserManual_Sensitivity.pdf) for more details). To this end, you should define your fourth random variable as a uniform random variable, and convert it to the target discrete random variable inside your model.

If you only have data, and the discrete variable has only a few possible outcomes, you can build a surrogate with the data that share the same outcome/label of the discrete variable. Then, you can follow the [definition of Sobol’ indices](https://en.wikipedia.org/wiki/Variance-based_sensitivity_analysis) to calculate the them. For example, suppose that your discrete variable X\_4 is a Bernoulli random variable that can only take the value 0 or 1 with probability 0.5 for each. Denote that Y=f(X\_1,X\_2,X\_3,X\_4) your computational model. Then, you can build a surrogate model \hat{f}\_0(X\_1,X\_2,X\_3) with the data having X\_4=0 and a second surrogate \hat{f}\_1(X\_1,X\_2,X\_3) for X\_4=1. Then, following the definition, the first-order and total Sobol’ indices are given by

S\_i = \frac{\mathbb{V}\left( \mathbb{E}\left(Y\mid X\_i\right)\right)}{\mathbb{V}(Y)}, \quad S^T\_i = 1-\frac{\mathbb{V}\left( \mathbb{E}\left(Y\mid X\_{\sim i}\right)\right)}{\mathbb{V}(Y)}. 

All the quantities in the equation above can be calculated by performing Monte-Carlo simulation on your two surrogate models: if a sample has X\_4=0, \hat{f}\_0 will be called. Otherwise, \hat{f}\_1 will be used. In a more practical way, you can define a new model with X\_4 following a uniform distribution between 0 and 1:

\hat{f}(x\_1,x\_2,x\_3,x\_4) = \begin{cases} &\hat{f}\_0(x\_1,x\_2,x\_3) \quad \text{if } 0\leq x\_4\<0.5\\ &\hat{f}\_1(x\_1,x\_2,x\_3) \quad \text{if } 0.5\leq x\_4 \leq 1 \end{cases}.

Then, you can use samping-based method (see Section 2.1.8 of the [manual](https://uqftp.ethz.ch/uqlab_doc_pdf/1.4.0/UserManual_Sensitivity.pdf) for more details) to calculate the Sobol’ indices for \hat{f}(X\_1,X\_2,X\_3,X\_4), which would be estimates of the Sobol’ indices of the original model f.
