Switchback Tests

Learn about switchback testing methodology and how to set up switchback experiments for marketplaces and network effect scenarios.

A switchback test switches an entire population back and forth between test and control treatments on a set cadence, instead of splitting the population into two fixed groups. Statsig compares the time windows when the population was in test against the windows when it was in control. Use a switchback test when one user's treatment changes the experience of other users, as in a two-sided marketplace, or when giving different users different variants isn't feasible for fairness, legal, or logistical reasons. If user experiences are independent, run a standard A/B test instead. Warehouse Native projects run switchback experiments with Switchback V2.

Switchback tests are common in marketplaces, where a traditional A/B test on one side of the marketplace can change the rest of the marketplace through network effects and bias the results. A switchback test often runs across multiple buckets, typically regions or other defined groups, that Statsig flips between test and control over the course of the experiment.

Example: rideshare pricing

Consider a rideshare platform that wants to test pricing. A standard A/B test splits riders into two groups: one with a higher price and one with a lower price. Riders with the lower price request rides at a higher rate and consume the available driver supply in an area. Riders with the higher price then face both a higher ride estimate and longer ETAs, which makes them even less likely to request a ride. The decreased request rate in the higher-price group could come from the higher prices or from the longer ETAs, so the experiment design has introduced bias into the results.

A switchback test resolves this. Instead of splitting users, 100% of riders and drivers in a given metro switch in and out of the new pricing plan hourly. The test then measures the impact on overall ride request rates during hours when prices were higher against hours when they were lower.

How Statsig computes switchback results

Statsig computes results in three steps: it attributes events to switchback buckets, calculates bucket-level and variant-level metrics from those events, then calculates the difference in means between test and control with bootstrapped confidence intervals.

Event attribution

Statsig attributes events to a bucket based on the timestamp and unit_id of the exposure, the length of the attribution window, and the timestamps of subsequent events for that unit_id. A time window and a grouping attribute define each bucket.

For example, Statsig exposes user 123 to bucket A at 9:15 AM and the test has an attribution window of 90 minutes. Statsig includes all events that user 123 triggers between 9:15 AM and 10:45 AM in the metric calculations for bucket A.

Bucket-level metrics

After Statsig has all the events for a bucket, it calculates the scorecard metrics from those events. In the following formulas, NjN_j is the number of units exposed to bucket jj, and XiX_i and YiY_i are the numerator and denominator values for unit ii.

For ratio metrics, the bucket value is the ratio of the summed numerator to the summed denominator:

R‾j=∑i=1NjXi∑i=1NjYi\overline{R}_j = \frac{\sum_{i=1}^{N_j} X_i}{\sum_{i=1}^{N_j} Y_i}

For sum and count metrics, Statsig uses the mean value per unit exposed to that bucket:

X‾j=∑i=1NjXiNj\overline{X}_j = \frac{\sum_{i=1}^{N_j} X_i}{N_j}

Variant-level metrics

Statsig calculates overall metric means for test and control by aggregating values across all buckets in that variant. If there are MM buckets in the test group, the mean value of a ratio metric is:

R‾test=∑j=1M∑i=1NjXi∑j=1M∑i=1NjYi\overline{R}_{test} = \frac{\sum_{j=1}^{M} \sum_{i=1}^{N_j} X_i}{\sum_{j=1}^{M} \sum_{i=1}^{N_j} Y_i}

The mean of a sum or count metric is:

X‾test=∑j=1M∑i=1NjXi∑j=1MNj\overline{X}_{test} = \frac{\sum_{j=1}^{M} \sum_{i=1}^{N_j} X_i}{\sum_{j=1}^{M} N_j}

Deltas and confidence intervals

Statsig calculates the treatment effect as an absolute delta and as a relative delta:

Δ=X‾test−X‾control\Delta = \overline{X}_{test} - \overline{X}_{control}
Δ%=X‾test−X‾controlX‾control×100%\Delta\% = \frac{\overline{X}_{test} - \overline{X}_{control}}{\overline{X}_{control}} \times 100\%

Statsig obtains the bootstrapped confidence intervals as follows:

  1. Draw a random sample of test buckets, the same size as the test group. Statsig draws with replacement, so a bucket can appear more than once in the sample. Draw a control sample from the control buckets the same way.
  2. Calculate the difference between the mean of the test sample and the mean of the control sample.
  3. Repeat steps one and two 10,000 times to produce a distribution of metric deltas.
  4. Take the 95% confidence interval as the range from the 2.5% quantile to the 97.5% quantile of that distribution.

In general, with significance level α\alpha and q(p)q(p) as the pp quantile of the bootstrapped deltas, the confidence interval is:

[,q!(α2), q!(1−α2)]\left[, q!\left(\tfrac{\alpha}{2}\right),\ q!\left(1 - \tfrac{\alpha}{2}\right) \right]

Set up a switchback test

You can set up a switchback test when you create your experiment. During the creation of an experiment, select the Experiment Type chip under Details in the Create New Experiment dialog. Then, select Switchback Test.

Switchback test configuration adds two aspects to the standard experiment setup:

  1. Targeting: The population or populations that you run your experiment on.
  2. Schedule: The switching frequency and the starting treatment for each pre-defined population.

Targeting

There are two ways to define targeting:

  • Targeting Gate: Specify a targeting gate to define your target experiment population, the same way you would for any other experiment. For how to target with a feature gate, go to Experiment Allocation and Targeting.
  • Bucketing Method: Bucket users with Manual Bucketing (pre-defined buckets) or with Randomized Bucketing (randomizing across an ID type).

To open these settings, select Add Targeting in the Treatments and Parameters section of the Setup tab.

With Manual Bucketing, you choose a Bucket Type, such as Country, Locale, or a custom field you log, and list the Bucket Values to switch. Use this option when you have a few pre-defined populations that you want to switch in and out of test and control over the course of the experiment.

With Randomized Bucketing, Statsig randomizes across the ID Type you choose, and Randomization Test % sets the share of units assigned to test. For example, choosing a custom ID such as CityID randomizes different CityIDs across test and control over the switchback windows. Use this option when you have a very large or changing number of experiment units to randomize across.

Randomized bucketing is an advanced feature. Contact the support team, your sales contact, or the Slack community so they can enable it.

Schedule

The Schedule section of experiment setup has these fields. Which fields appear depends on the bucketing method you select.

Schedule section with a 60-minute window, burn-in and burn-out periods, and a control and test timeline

Reading results

Diagnostics and metric lift results for switchback tests resemble Statsig's traditional A/B tests, with a few differences:

  • No hourly results: Because a switchback experiment starts with all-test or all-control exposures, Statsig disables hourly results until there is a meaningful amount of data. Use the Diagnostics tab in the meantime to verify that checks arrive and bucket as expected.
  • No time series: Switchback tests don't support the Daily or Days Since First Exposure time series. The bootstrapping methodology pools all available days together to achieve sufficient statistical power.
  • No dimension breakdown: Switchback tests don't support breaking down a metric by user property or event property.
  • No CUPED or sequential testing: Switchback tests don't yet support CUPED and sequential testing.

Switchback experiment pulse results showing bucket-level metrics

Was this helpful?

For AI agents: a documentation index is available at /llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

On this page