8/17
Part 4 of 7 · Permutation testsLearn and do

A permutation test checks the answer without assuming a shape

The t-test leans on the CLT, and the distributions lesson showed how slowly that works for skewed order values. A permutation test needs no shape. If the two groups really come from the same distribution, which SciPy's docs give as the null, then the labels don't matter, so shuffle them. The p-value counts how many shuffled gaps are at least as extreme as the real one.

Here are 15 orders a side from an old and a new checkout, with order values skewed like the shop's:

rng = random.Random(10)
# order values, old checkout
old = [round(math.exp(rng.gauss(4, 1)), 2) for _ in range(15)]
# order values, new checkout
new = [round(math.exp(rng.gauss(4.4, 1)), 2) for _ in range(15)]
t, df = welch(mean(new), stdev(new), 15, mean(old), stdev(old), 15)
print(f"means ${mean(old):.0f} and ${mean(new):.0f}")
print(f"Welch p = {t_two_sided_p(t, df):.3f}, permutation p = {permutation_p(new, old, 10_000, rng):.3f}")
Predict

The new checkout's average order is far higher. With 15 skewed orders a side, is that convincing?

Pick one to see what it prints.
Pick an answer above to see the rest