Skip to contents

Shuffles the combined samples n_permutations times to construct the null distribution of the chosen test statistic. coin's coin::oneway_test(distribution = "approximate") implements the same test with a Monte-Carlo null; it is delegated to when coin is installed and statistic is the default "mean_diff" (the rmorie API allows arbitrary f(g1, g2) which coin does not expose, so a custom statistic falls back to the inline shuffle loop). The inline path keeps the full null distribution which downstream MRM code consumes.

Usage

permutation_test(
  group1,
  group2,
  statistic = "mean_diff",
  n_permutations = 9999L,
  alternative = "two-sided",
  seed = 42L
)

Arguments

group1, group2

Numeric vectors.

statistic

Either "mean_diff", "median_diff", "t_stat", or a function f(g1, g2) -> scalar.

n_permutations

Number of permutations.

alternative

"two-sided", "greater", or "less".

seed

Random seed.

Value

A morie_permutation_test_result.

Examples

set.seed(1)
str(permutation_test(rnorm(25), rnorm(25, 0.5),
                     n_permutations = 499L), max.level = 1)
#> List of 7
#>  $ observed_statistic: num -0.0536
#>  $ p_value           : num 0.88
#>  $ null_distribution : num [1:499] 0.2587 0.2831 0.197 0.0243 0.4233 ...
#>  $ n_permutations    : int 499
#>  $ alternative       : chr "two-sided"
#>  $ ci_lower          : num NA
#>  $ ci_upper          : num NA
#>  - attr(*, "class")= chr [1:2] "morie_permutation_test_result" "list"