A/B tests with ratio metrics. The delta method

Nikolay Nazarov8 Jun 2023

Problem

Many product metrics are ratios of two sums over users, such as average check (purchase amount per purchase) or CTR (clicks per impression). Users are randomized, but the metric is computed over purchases or impressions, and the observations of one user are dependent. The Student's t-test assumes independence, so on raw purchases it reports differences that do not exist: in the article's simulation the type I error rate at the 0.05 level was 0.2.

Example from the article: a group has two customers, one with a 500-ruble purchase and one with purchases of 400 and 300 rubles. The average check is 400 rubles, computed over purchases, not customers.

Solution in brief

Treat each user as one object. Either bootstrap by users (correct but slow on large data) or use the delta method: estimate the variance of the ratio from per-user numerators and denominators and plug it into a t-statistic. A/A simulations show that the delta method keeps the error rate at the chosen level and finds a real effect.

Questions this case answers
  • How to test the difference of a metric defined as a ratio of two per-unit sums when the observations of one randomization unit are dependent
  • How to verify with a simulation that a hypothesis test keeps its false-positive rate at the chosen level
  • How to test the difference in a ratio metric such as average check or CTR between A/B groups when one user produces many observations
  • How to check that a statistical test controls the type I error on your metric before trusting it

Tools and methods

  • Delta method — variance of a ratio metric from per-user sums, used in a normal-approximation test
  • Bootstrap by objects — resampling users, not observations
  • Student's t-test — fails on raw ratio data
  • A/A simulation — checks the p-value distribution and the type I error rate of a criterion
  • NumPy, SciPy — simulations
Continue reading — it's free

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