Computes a permutation-based p-value for a given super sample.
The statistic used for the permutation test can be specified
via the stat_fun argument.
Details
The function computes the statistic on the observed data and compares it to the distribution of statistics computed on permuted samples. Under the null hypothesis that group labels are exchangeable, this provides an exact test (subject to Monte Carlo error).
The permutation test:
Computes the test statistic on the observed data
Randomly shuffles group assignments while preserving sample sizes
Recomputes the test statistic on each permuted dataset
Calculates the p-value as the proportion of permuted statistics that exceed the observed statistic
This approach is computationally efficient and does not require parameter estimation or synthetic data generation.