knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(funStatTest)
#| include: no # fix seed for simulations set.seed(123456)
The funStatTest
package implements various statistics for two sample comparison testing regarding functional data.
This package is developed by:
It implements statistics (and related experiments) introduced and used in [@smida2022].
Here are some functions used to simulate clustered trajectories of functional data based on the Karhunen-Loève decomposition.
The functional data simulation process is described in [@smida2022] (section 3.1).
simu_vec <- simul_traj(100) plot(simu_vec, xlab = "point", ylab = "value")
simu_data <- simul_data( n_point = 100, n_obs1 = 50, n_obs2 = 75, c_val = 10, delta_shape = "constant", distrib = "normal" ) str(simu_data)
# constant delta simu_data <- simul_data( n_point = 100, n_obs1 = 50, n_obs2 = 75, c_val = 5, delta_shape = "constant", distrib = "normal" ) plot_simu(simu_data) # linear delta simu_data <- simul_data( n_point = 100, n_obs1 = 50, n_obs2 = 75, c_val = 5, delta_shape = "linear", distrib = "normal" ) plot_simu(simu_data) # quadratic delta simu_data <- simul_data( n_point = 100, n_obs1 = 50, n_obs2 = 75, c_val = 5, delta_shape = "quadratic", distrib = "normal" ) plot_simu(simu_data)
The $MO$ median statistic [@smida2022] is implemented in the stat_mo()
function.
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 stat_mo(MatX, MatY)
The $MED$ median statistic [@smida2022] is implemented in the stat_med()
function.
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 stat_med(MatX, MatY)
The Wilcoxon-Mann-Whitney statistic [@chakraborty2015] (noted $WMW$ in [@smida2022]) is implemented in the stat_wmw()
function.
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 stat_wmw(MatX, MatY)
The Horváth-Kokoszka-Reeder statistics [@horvath2013] (noted $HKR1$ and $HKR2$ in [@smida2022]) are implemented in the stat_hkr()
function.
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 stat_hkr(MatX, MatY)
The Cuevas-Febrero-Fraiman statistic [@cuevas2004] (noted $CFF$ in [@smida2022]) is implemented in the stat_cff()
function.
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 stat_cff(MatX, MatY)
The function comp_stat()
allows to compute multiple statistics defined above in a single call on the same data.
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 res <- comp_stat(MatX, MatY, stat = c("mo", "med", "wmw", "hkr", "cff")) res
P-values associated to the different statistics defined above can be computed with the permutation-based method as follow:
# simulate small data for the example simu_data <- simul_data( n_point = 20, n_obs1 = 4, n_obs2 = 5, c_val = 10, delta_shape = "constant", distrib = "normal" ) MatX <- simu_data$mat_sample1 MatY <- simu_data$mat_sample2 res <- permut_pval( MatX, MatY, n_perm = 100, stat = c("mo", "med", "wmw", "hkr", "cff"), verbose = TRUE) res
:warning: computing p-values based on permutations may take some time (for large data or when using a large number of simulations. :warning:
We use our simulation scheme with permutation-based p-values computation to run a power analysis to evaluate the different statistics.
# simulate a few small data for the example res <- power_exp( n_simu = 20, alpha = 0.05, n_perm = 100, stat = c("mo", "med", "wmw", "hkr", "cff"), n_point = 25, n_obs1 = 4, n_obs2 = 5, c_val = 10, delta_shape = "constant", distrib = "normal", max_iter = 10000, verbose = FALSE ) res$power_res
::: {#refs} :::
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.