Clustered Standard Errors in AB Tests

Matteo Courthoud17 Mar 2024

Problem

An online platform tests a feature but randomizes customers, not orders, so that each customer sees one experience. The analyst then regresses revenue per order on the treatment flag and reads the standard error from the regression table. That error assumes every order is independent. Orders of one customer always share the same treatment, so the estimate varies much more than the table says and noise can pass for a real effect. The same happens in geo-experiments and when whole brands are treated and outcomes are read per article.

Example from the article: a related-articles carousel at checkout was randomized by customer (50% chance each). In simulated data with 3000 orders from 100 customers, a plain regression reports an effect of -1.63€ per order with p = 0.005. The true effect is zero.

Solution in brief

Compute standard errors that allow correlation among observations of the same cluster (the randomization unit). In statsmodels this is one argument, and the point estimate stays the same. A bootstrap that resamples whole clusters gives a check on the result.

Questions this case answers
  • How to compute valid standard errors and p-values when the randomization unit is a group but outcomes are observed at the level of individual records
  • How to get correct standard errors and p-values when users are randomized but the metric is measured per order?
  • How to check that the standard errors in an A/B test readout are not too small?
  • How to run a significance test when treatment is assigned to groups such as customers or regions?

Tools and methods

  • Cluster-robust standard errors — standard errors that allow correlated residuals inside a cluster, here a customer
  • Cluster bootstrap — resample customers, not orders, to estimate the spread of the effect
  • Re-randomization simulation — redraw the assignment many times to learn the true spread (possible only in simulated data)
  • statsmodels — ols with cov_type='cluster'
Continue reading — it's free

Google or a one-time email code. No password.