Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA054 · Hypothesis test

Paired randomization and permutation tests

Calibrates a system-comparison statistic by transformations justified under a specified null.

Runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through evaluate.paired_metric, ttest.paired. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Calibrates a system-comparison statistic by transformations justified under a specified null.

Question / hypotheses

H0 must imply the proposed label swaps or sign flips are exchangeable; merely equal expected performance is not sufficient for every permutation design.

Architecture / computational structure

Identify the transformations allowed by the design. For the paired example, enumerate all 2^n sign vectors, recompute the absolute mean difference, and count outcomes at least as extreme as observed. Full enumeration includes the identity once; random sampling uses the stated Monte Carlo correction.

Assumptions

Use the randomization unit from the design or a justified exchangeability model. Preserve paired observations and dependence blocks. Include preprocessing or tuning in the statistic when required by the null design.

Formula / computational definition

pMC=1+∑b=1B1{Tb∗≥Tobs}B+1,pexact=∑g∈G1{T(gX)≥Tobs}∣G∣.p_{MC}=\frac{1+\sum_{b=1}^{B}\mathbf1\{T_b^*\ge T_{obs}\}}{B+1},\qquad p_{exact}=\frac{\sum_{g\in\mathcal G}\mathbf1\{T(gX)\ge T_{obs}\}}{|\mathcal G|}.

Parameters and notation

T may be a one-sided effect or absolute two-sided effect. The first formula uses B randomly drawn transformations plus the observed configuration; the second enumerates the complete group G, including the identity, so it does not add a second identity correction. Permutation group, B, and tail choice are fixed before inspecting results.

Fitting, fine-tuning, and adaptation

There is no model fine-tuning step. Freeze the compared systems, test statistic, tail, and independent unit before testing. Exchangeability under a randomized paired design or a suitable symmetric-difference model justifies sign flips; mean equality alone does not. Changing a data-selected statistic or fitting step requires reproducing that selection within the valid randomization scheme.

How to use and calibrate

Specify the null and allowable transformations, generate null statistics, and report the effect with its calibrated p-value. Exact enumeration is possible for small designs.

Example application

Compare two fixed retrieval systems using randomized within-query assignments under an appropriate paired null.

Interpretation / pitfalls

Watch out

Sign flipping assumes more than arbitrary mean equality in many observational designs. Repeatedly choosing the best test statistic or model without correction invalidates a simple final p-value.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy

import numpy as np,itertools
d=np.array([.1,.2,-.05,.15]); observed=abs(d.mean())
null=np.array([abs(np.mean(d*np.array(s))) for s in itertools.product([-1,1],repeat=len(d))])
print(np.mean(null>=observed-1e-12))  # exact sign-flip enumeration including identity
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

d <- c(.1,.2,-.05,.15); S <- as.matrix(expand.grid(rep(list(c(-1,1)),length(d))))
null <- abs(as.vector(S%*%d)/length(d)); print(mean(null>=abs(mean(d))-1e-12))

Sources

From the CodeSplash reference, entry EVA054.