# \donttest{
# Test case: the Ishigami function.
n <- 20 # very few input-output samples
p <- 3 # nb of input variables
########################################
### PRELIMINARY SENSITIVITY ANALYSIS ###
########################################
X <- matrix(runif(n*p), n, p)
sensi <- sensiHSIC(model=ishigami.fun, X)
print(sensi)
plot(sensi)
title("GSA for the Ishigami function")
#############################
### TESTS OF INDEPENDENCE ###
#############################
test.asymp <- testHSIC(sensi)
test.perm <- testHSIC(sensi, test.method="Permutation")
test.seq.screening <- testHSIC(sensi, test.method="Seq_Permutation")
test.seq.ranking <- testHSIC(sensi, test.method="Seq_Permutation",
seq.options=list(criterion="ranking"))
test.seq.both <- testHSIC(sensi, test.method="Seq_Permutation",
seq.options=list(criterion="both"))
test.gamma <- testHSIC(sensi, test.method="Gamma")
# comparison of p-values
res <- rbind( t(as.matrix(test.asymp$pval)), t(as.matrix(test.perm$pval)),
t(as.matrix(test.seq.screening$pval)), t(as.matrix(test.seq.ranking$pval)),
t(as.matrix(test.seq.both$pval)), t(as.matrix(test.gamma$pval)) )
rownames(res) <- c("asymp", "perm", "seq_perm_screening",
"seq_perm_ranking", "seq_perm_both", "gamma")
res
# Conclusion: n is too small for the asymptotic test.
# Take n=200 and all four test methods will provide very close p-values.
#####################
### VISUALIZATION ###
#####################
# simulated values of HSIC indices under H0 (random permutations)
Hperm <- t(unname(test.perm$Hperm))
for(i in 1:p){
# histogram of the test statistic under H0 (random permutations)
title <- paste0("Histogram of S", i, " = HSIC(X", i, ",Y)")
hist(Hperm[,i], probability=TRUE,
nclass=70, main=title, xlab="", ylab="", col="cyan")
# asymptotic Gamma distribution
shape.asymp <- test.asymp$param[i, "shape"]
scale.asymp <- test.asymp$param[i, "scale"]
xx <- seq(0, max(Hperm[,i]), length.out=200)
dens.asymp <- dgamma(xx, shape=shape.asymp, scale=scale.asymp)
lines(xx, dens.asymp, lwd=2, col="darkorchid")
# finite-sample Gamma distribution
shape.perm <- test.gamma$param[i, "shape"]
scale.perm <- test.gamma$param[i, "scale"]
dens.perm <- dgamma(xx, shape=shape.perm, scale=scale.perm)
lines(xx, dens.perm, lwd=2, col="blue")
all.cap <- c("Asymptotic Gamma distribution", "Finite-sample Gamma distribution")
all.col <- c("darkorchid", "blue")
legend("topright", legend=all.cap, col=all.col, lwd=2, y.intersp=1.3)
}
# }
Run the code above in your browser using DataLab