# Test case : the non-monotonic Sobol g-function
# The method of sobol requires 2 samples
# There are 8 factors, all following the uniform distribution
# on [0,1]
library(boot)
n <- 1000
X1 <- data.frame(matrix(runif(8 * n), nrow = n))
X2 <- data.frame(matrix(runif(8 * n), nrow = n))
# sensitivity analysis
x <- sobolmartinez(model = sobol.fun, X1, X2, nboot = 0)
print(x)
plot(x)
library(ggplot2)
ggplot(x)
# \donttest{
# Only for demonstration purposes: a model function returning a matrix
sobol.fun_matrix <- function(X){
res_vector <- sobol.fun(X)
cbind(res_vector, 2 * res_vector)
}
x_matrix <- sobolmartinez(model = sobol.fun_matrix, X1, X2)
plot(x_matrix, y_col = 2)
title(main = "y_col = 2")
# Also only for demonstration purposes: a model function returning a
# three-dimensional array
sobol.fun_array <- function(X){
res_vector <- sobol.fun(X)
res_matrix <- cbind(res_vector, 2 * res_vector)
array(data = c(res_matrix, 5 * res_matrix),
dim = c(length(res_vector), 2, 2))
}
x_array <- sobolmartinez(model = sobol.fun_array, X1, X2)
plot(x_array, y_col = 2, y_dim3 = 2)
title(main = "y_col = 2, y_dim3 = 2")
# }
Run the code above in your browser using DataLab