---
title: Switchback Tests
description: Learn about switchback testing methodology and how to set up switchback experiments for marketplaces and network effect scenarios.
product: general
lang: en
token_estimate: 2406
---
# Switchback Tests

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](https://docs.statsig.com/guides/abn-tests) instead. Warehouse Native projects run switchback experiments with [Switchback V2](https://docs.statsig.com/experiments/types/switchback-v2).

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

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, $N_j$ is the number of units exposed to bucket $j$, and $X_i$ and $Y_i$ are the numerator and denominator values for unit $i$.

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

$$
\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:

$$
\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 $M$ buckets in the test group, the mean value of a ratio metric is:

$$
\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:

$$
\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:

$$
\Delta = \overline{X}_{test} - \overline{X}_{control}
$$

$$
\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)$ as the $p$ quantile of the bootstrapped deltas, the confidence interval is:

$$
\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](https://docs.statsig.com/experiments/setup/allocation-and-targeting#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.

> **Info:**
>
> Randomized bucketing is an advanced feature. Contact the support team, your sales contact, or the [Slack community](https://statsig.com/slack) 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.

| Field | Applies to | Description |
| --- | --- | --- |
| Experiment Start Time | Both bucketing methods | When the switchback test begins. |
| Duration in Days | Both bucketing methods | How long the test runs, in days. |
| Stop Experiment upon reaching Target Duration | Both bucketing methods | Ends the experiment automatically when it reaches the duration. |
| Assignment Window Size in Minutes | Both bucketing methods | The length of each switchback window. |
| Burn In and Burn Out Period in Minutes | Both bucketing methods | Time intervals at the start and end of each switchback window whose exposures Statsig discards from analysis. Use these when the previous treatment might bleed over while a population switches between test and control. |
| Timezone | Both bucketing methods | The time zone the schedule timeline displays in. |
| Starts With Control / Starts With Test | Manual Bucketing only | The treatment group each bucket starts in. Select **Change Phase** to move a bucket. |

![Schedule section with a 60-minute window, burn-in and burn-out periods, and a control and test timeline](https://docs.statsig.com/images/experiments/types/switchback-tests/67ed1aee-f5aa-49b6-b684-a9919b59d5ca.png)

## 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](https://docs.statsig.com/images/experiments/types/switchback-tests/657cce2d-22b0-41cf-8b43-2d3f05cfefb8.png)

