From 88a6a3a0735b43a8d3c6abbcb4cf425d4e60cb21 Mon Sep 17 00:00:00 2001
From: Ghislain Durif <gd.dev@libertymail.net>
Date: Thu, 23 Feb 2023 16:07:15 +0100
Subject: [PATCH] WIP: pvalues computation by permutation

---
 dev/flat_package.Rmd | 72 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/dev/flat_package.Rmd b/dev/flat_package.Rmd
index 4cb1920..5d6eebf 100644
--- a/dev/flat_package.Rmd
+++ b/dev/flat_package.Rmd
@@ -269,7 +269,9 @@ str(simu_data)
 #' 
 #' @param simu list, output of [funStatTest::simul_data()]
 #' 
-#' @seealso [funStatTest::simulate_data()]
+#' @return the ggplot2 graph of simulated tajectories.
+#' 
+#' @seealso [funStatTest::simul_data()]
 #' 
 #' @inherit authorship author
 #' 
@@ -380,6 +382,8 @@ The $MO$ median statistic [1] is implemented in the `stat_mo()` function.
 #' [<DOI:10.1080/10485252.2022.2064997>](https://dx.doi.org/10.1080/10485252.2022.2064997) 
 #' [<hal-03658578>](https://hal.science/hal-03658578)
 #' 
+#' @seealso [funStatTest::permut_pval()]
+#' 
 #' @export
 #' 
 #' @examples
@@ -473,6 +477,8 @@ The $MED$ median statistic [1] is implemented in the `stat_med()` function.
 #' [<DOI:10.1080/10485252.2022.2064997>](https://dx.doi.org/10.1080/10485252.2022.2064997) 
 #' [<hal-03658578>](https://hal.science/hal-03658578)
 #' 
+#' @seealso [funStatTest::permut_pval()]
+#' 
 #' @export
 #' 
 #' @examples
@@ -572,6 +578,9 @@ The Wilcoxon-Mann-Whitney statistic [2] (noted $WMW$ in [1]) is implemented in t
 #' 34:2, 520-553,  
 #' [<DOI:10.1080/10485252.2022.2064997>](https://dx.doi.org/10.1080/10485252.2022.2064997) 
 #' [<hal-03658578>](https://hal.science/hal-03658578)
+#' 
+#' @seealso [funStatTest::permut_pval()]
+#' 
 #' @export
 #' 
 #' @examples
@@ -660,6 +669,8 @@ The Horváth-Kokoszka-Reeder statistics [3] (noted $HKR1$ and $HKR2$ in [1]) are
 #' [<DOI:10.1080/10485252.2022.2064997>](https://dx.doi.org/10.1080/10485252.2022.2064997) 
 #' [<hal-03658578>](https://hal.science/hal-03658578)
 #' 
+#' @seealso [funStatTest::permut_pval()]
+#' 
 #' @export
 #' 
 #' @examples
@@ -783,6 +794,8 @@ The Cuevas-Febrero-Fraiman statistic [4] (noted $CFF$ in [1]) ais implemented in
 #' [<DOI:10.1080/10485252.2022.2064997>](https://dx.doi.org/10.1080/10485252.2022.2064997) 
 #' [<hal-03658578>](https://hal.science/hal-03658578)
 #' 
+#' @seealso [funStatTest::permut_pval()]
+#' 
 #' @export
 #' 
 #' @examples
@@ -821,8 +834,65 @@ MatY <- simu_data$mat_sample2
 stat_cff(MatX, MatY)
 ```
 
+## Permutation-based computation of p-values
+
+```{r function-permut_pval}
+#' Permutation-based computation of p-values
+#' 
+#' @filename pvalues.R
+#' 
+#' @description Computation of the p-values associated to any statistics
+#' described in the package with the permutation methods. See Smida et al 
+#' (2022) for more details.
+#' 
+#' @param MatX numeric matrix of dimension `n_point x n` containing `n` 
+#' trajectories (in columns) of size `n_point` (in rows).
+#' @param MatY numeric matrix of dimension `n_point x m` containing `m` 
+#' trajectories (in columns) of size `n_point` (in rows).
+#' @param stat character string or vector of character string, name of the 
+#' statistics for which the p-values will be computed, among `"mo"`, `"med"`,
+#' `"wmw"`, `"hkr"`, `"cff"`.
+#' @param n_perm interger, number of permutation to compute the p-values.
+#' 
+#' @return numeric value corresponding to the WMW statistic value
+#' 
+#' @inherit authorship author
+#' 
+#' @references
+#' Zaineb Smida, Lionel Cucala, Ali Gannoun & Ghislain Durif (2022) 
+#' A median test for functional data, Journal of Nonparametric Statistics, 
+#' 34:2, 520-553,  
+#' [<DOI:10.1080/10485252.2022.2064997>](https://dx.doi.org/10.1080/10485252.2022.2064997) 
+#' [<hal-03658578>](https://hal.science/hal-03658578)
+#' 
+#' @seealso [funStatTest::stat_mo()], [funStatTest::stat_med()], 
+#' [funStatTest::stat_wmw()], [funStatTest::stat_hkr()], 
+#' [funStatTest::stat_cff()]
+#' 
+#' @export
+#' 
+#' @examples
+permut_pval <- function(MatX, MatY, n_perm = 100, stat = c("mo", "med")) {
+    assert_count(n_perm, positive = TRUE)
+    assert_choice(stat, c("mo", "med", "wmw", "hkr", "cff"))
+}
+```
+
+```{r tests-permut_pval}
+test_that("permut_pval", {
+    expect_true(TRUE)
+})
+```
 
+```{r examples-permut_pval}
+simu_data <- simul_data(
+    n_point = 100, n_obs1 = 50, n_obs2 = 75, c_val = 10, 
+    delta_shape = "constant", distrib = "normal"
+)
 
+MatX <- simu_data$mat_sample1
+MatY <- simu_data$mat_sample2
+```
 
 ## References
 
-- 
GitLab