How to use sobol2002 for sensitivity analysis in R?

I have a very basic understanding of R and stat so my question may sound very simple. I am trying to do a sensitivity analysis on a model that takes 30+ input parameters. The model is created in R.

From my understanding, if I want to use sobolo2002 - my input should be X1 and X2.

How do I generate X1 and X2 for my model?

From what I have read - my initial task would be to determine the range and distribution for each input variable and generate sample points form the distribution of the inputs. The model will be fed with the sample elements and a set of output is produced. These model evaluations are then used as a basis for SA.

Is this the case for sobol2002 as well?

I did read the answer here to understand sobol package in R

Understanding Sobol in R Package Sensitivity

but I still have trouble understanding how to link my input variables in this function.

Any help/hints/idea would be really appreciated.

Sobol Sensitivity Indices are estimated using data points representing the uncertainty on input variables. For this, you need to define a distribution for each of your input variables (which should be independent, by the way).

Each column in X1 and X2 corresponds to an input variable. Each row is a set of input values in input of your model. (By the way, your model needs to accept a matrix input. If not, you need to build a wrapper around it).

Let's have a simple example with the analysis of model f which does just the sum of its inputs:

f <- function(x) {rowSums(x)}


Let's assume it has 3 input variables with uniform distribution between 0 and 1.

n <- 1000
X1 <- data.frame(matrix(runif(3*n), nrow=n))
X2 <- data.frame(matrix(runif(3*n), nrow=n))


X1 and X2 are just the base input points used for the statistical estimation of the indices.

Note sobol2002 will not only apply f to points in X1 and X2 but also to points derived from combinations of these dataframes.

Be careful: the sensitivity package documentation tells that sobol2002 suffers from conditioning problem and advices to use other functions from the package in certain cases: https://cran.r-project.org/web/packages/sensitivity/sensitivity.pdf