Randomize what you can, block what you cannot

Today let's look at what actually keeps a treatment group and a control group comparable, and what can quietly throw that off even when nothing was done wrong.

Here is the example we will use throughout. A checkout page shows 24 returning shoppers one of two versions. 12 of them, the treatment group, see a new one-click checkout button. The other 12, the control group, see the current multi-step checkout. What gets measured is each shopper's total spend during that visit.

Before any of that happens, every shopper already carries two things that have nothing to do with which checkout they end up seeing. Each one has a cart value, somewhere between $18 and $210, and a device, desktop or mobile.

Here are all 24 shoppers, plotted by cart value against spend, with each dot colored by device.

Spend climbs steadily as cart value rises, and the Pearson r in the corner puts a number on how steadily. Each dot's color marks the other fact that was already true about that shopper, desktop or mobile, long before either checkout version was ever shown to anyone.

The cart value every shopper already has, before the test even starts

Cart value is what experimenters call a nuisance variable. It is known before anyone is assigned a checkout version, it affects the outcome you actually care about, and it has nothing to do with the treatment itself.

Here, cart value affects spend in the most direct way possible. A shopper who already has $200 worth of items sitting in their cart is going to spend more at checkout than one who has $20 in there, no matter which checkout button they end up clicking. Pull the numbers for all 24 shoppers and look at them side by side.

RInteractive R
# Look at the 24 shoppers' cart value, device and spend together cart_value <- c(76, 39, 106, 210, 153, 153, 179, 27, 152, 184, 104, 186, 40, 180, 80, 201, 43, 75, 117, 191, 18, 149, 98, 41) device <- c("desktop", "desktop", "mobile", "desktop", "desktop", "desktop", "desktop", "desktop", "mobile", "desktop", "mobile", "desktop", "desktop", "mobile", "desktop", "mobile", "desktop", "mobile", "desktop", "desktop", "desktop", "desktop", "mobile", "mobile") desktop_ind <- as.numeric(device == "desktop") set.seed(55) noise <- rnorm(24, 0, 9) spend_base <- round(25 + 0.55 * cart_value + 12 * desktop_ind + noise, 2) treatment <- rep(c(1, 0), c(12, 12)) # the actual 12 who saw each version spend <- round(spend_base + 15 * treatment, 2) round(cor(cart_value, spend), 3) #> [1] 0.952 shoppers <- data.frame(shopper = 1:24, cart_value, device, spend) shoppers #> shopper cart_value device spend #> 1 1 76 desktop 94.88 #> 2 2 39 desktop 57.14 #> 3 3 106 mobile 99.66 #> 4 4 210 desktop 157.43 #> 5 5 153 desktop 136.17 #> 6 6 153 desktop 146.85 #> 7 7 179 desktop 145.90 #> 8 8 27 desktop 65.96 #> 9 9 152 mobile 126.35 #> 10 10 184 desktop 154.99 #> 11 11 104 mobile 96.76 #> 12 12 186 desktop 146.71 #> 13 13 40 desktop 40.32 #> 14 14 180 mobile 120.75 #> 15 15 80 desktop 75.26 #> 16 16 201 mobile 132.25 #> 17 17 43 desktop 81.85 #> 18 18 75 mobile 76.09 #> 19 19 117 desktop 103.92 #> 20 20 191 desktop 150.99 #> 21 21 18 desktop 33.23 #> 22 22 149 desktop 132.42 #> 23 23 98 mobile 86.28 #> 24 24 41 mobile 57.14

  

spend_base is what each shopper would spend with no checkout effect at all: their cart value, scaled up a bit, plus a touch of random noise, since real spending always wobbles a little even between shoppers with the same cart value. treatment marks the 12 shoppers who actually saw the new button with a 1 and the other 12 with a 0, and spend adds a real $15 to whichever 12 that happens to be. That $15 is the true effect of the new checkout button, built into this simulation on purpose, so every estimate from here on can be checked against a known right answer.

cor(cart_value, spend) comes out to 0.952. That is about as strong as a correlation gets outside of a formula: a shopper's cart value very nearly tells you what they are going to spend, regardless of which checkout button they happened to see.

This is exactly the kind of variable randomization is supposed to handle. Randomization's job, stated precisely, is this: it makes the treatment and control groups comparable on cart value, on device, and on every other nuisance variable, including ones nobody measured or even thought to look for, in expectation. "In expectation" means averaged over many hypothetical repeats of the very same coin flip that decided who got which checkout, not a guarantee about this one real assignment sitting in the table above.