Compute a paired comparison with an exact sign-flip test
Implement paired_report(baseline, candidate) for dictionaries mapping identical case IDs to finite scores where higher is better, returning paired effect counts and a small exact two-sided sign-flip p-value.
Your task
- Require matching nonempty dictionaries with 1 to 16 identical case IDs and finite int/float scores. Reject booleans and invalid inputs with ValueError.
- Sort case IDs for deterministic pairing. Compute candidate minus baseline for each case.
- Return n, mean_delta, wins, ties, losses, and p_value. Ties are exact zero differences.
- Enumerate every assignment of -1/+1 signs to the paired differences. Count an assignment as extreme when its absolute mean is at least the observed absolute mean minus 1e-12.
- Divide extreme assignments by 2**n. Document that validity requires exchangeable pair signs under the null and independent units appropriate to the study.
Examples
EXAMPLE 1
InputFour cases change from score 0 to score 1
Outputmean_delta=1.0, wins=4, ties=0, losses=0, p_value=0.125
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor