# Understanding Sobol in R Package Sensitivity

Sobol method quantifies the contributions of input variance to output variance. For example, given a model with two inputs and one output, one might find that 70% of the output variance is caused by the variance in the first input, 20% by the variance in the second, and 10% due to interactions between the two.

In R package "Sensitivity", a sample script of implementing Sobol method as below

library("sensitivity")
n<-1000
X1<-data.frame(matrix(runif(8*n), nrow=n))
X2<-data.frame(matrix(runif(8*n), nrow=n))
sa<-sobol2002(model=NULL, X1, X2, nboot=10)


I thought X1 is output matrix, and X2 is input matrix, so I could run analysis on different dimension of X1 and X2. but the function requires the same dimension of X1 and X2.

May I get intuitive explanation on what are X1 and X2?

## 2 Answers

X1 and X2 are both a subset of your input matrix. The method requires two samples. If your model runs in R you can use the model = your.model. Example from the package, slightly adapted

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

# Sensitivity analysis
x <- sobol2002(model = sobol.fun, X1, X2, nboot = 100)
print(x)
plot(x)


if your model runs in a different programm you need to use the function tell. You have to set the model=NULL

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

#Sensitivity analysis
x <- sobol2002(model = NULL, X1, X2, nboot = 100)
y <- ishigami.fun(x\$X)
tell(x,y)
print(x)
plot(x)


The sensitivity package contains several advanced methods for sensitivity analysis. As far as I've understood, the cleverness lies in getting as accurate estimates of sensitivity with as few model evaluations as possible.

The sobol2002 function and others use an approach that takes two input matrices $$A$$ and $$B$$, both of with $$N$$ rows and $$k$$ columns. Here, $$k$$ is the number of model parameters (factors) and $$N$$ is the number of model evaluations.

The two matrices are combined to obtain random parameter sets that differ only in one parameter. This is achieved by replacing the $$i$$-th column in $$A$$ with the $$i$$-th column in $$B$$. This gives $$k$$ matrices $$A_B^{(i)}$$.

The model is then evaluated for the $$kN$$ rows from the matrices $$A_B^{(1)} \dots A_B^{(k)}$$. Intuitively, this allows to assess the variation of the model measurements when varying each of the factors while keeping the others fixed.

The paper by Saltelli et al. [1] gives a concise introduction.

[1] Saltelli, Andrea, et al. "Variance based sensitivity analysis of model output. Design and estimator for the total sensitivity index." Computer Physics Communications 181.2 (2010): 259-270.