FDE Times dataFDE jobs open 922▼2 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 64Companies hiring 201Remote-friendly 23%Median US pay $202kTop hirer Databricks 113
中文VI

The newspaper of the Forward Deployed Engineer

Guides

How 30 minutes of carryover can erase a real effect

A Python switchback simulation shows how window length, burn-in and clustered errors decide the number you report to a client.

ShareLinkedInFacebookX

In brief

  • When users affect one another, randomize time instead of users.
  • In this simulation, carryover from the previous mode pulls the result toward 0; burn-in fixes that, but costs data.
  • For more power, run more days and adjust for time of day; extra records within each window help very little.
Horizontal bar chart: the true effect is a 4-minute reduction, with 30 minutes of carryover. A 30-minute window measures 0, a 60-minute window 2, a 120-minute window 3 and a 240-minute window 3.5. A 120-minute window with a 30-minute burn-in cut gives about 4.
The shorter the window, the further the measured reduction falls short of the true 4 minutes; with a 120-minute window, cutting a 30-minute burn-in brings the result to about 4. Source: hand calculations and a Python simulation using hypothetical data from the article.

A simulation study published in 2026 shows how wrong one kind of measurement can go: at the top of the carryover range tested, bias can exceed the true effect and flip the sign of the estimate. A useful improvement is then recorded as harmful.

The measurement is the switchback test. Consider it whenever a client’s product makes users affect one another, as on a marketplace. If their experiences are independent, stick with an ordinary A/B test.

This guide builds a simulated switchback on your laptop, where the right answer is known in advance. You can see which measurements go wrong, and by how much, before making the mistake on real data.

Why not split the drivers in half?

Take a hypothetical delivery client that wants to try a new dispatch algorithm. If half the orders use it, they still compete with the other half for the same pool of drivers. When the new group gets the closer drivers, the old group slows down, and the gap widens even though the system as a whole may be no better.

A switchback therefore moves the whole city to one mode for a window, then draws again for the next window. The price is carryover, the lingering effect of the previous mode: wherever the old algorithm placed the drivers, that is where they are when you switch.

Do the arithmetic before you write code

Suppose the new algorithm cuts delivery time by 4 minutes, and the first 30 minutes after each switch still carry the previous mode’s results. With a 50/50 draw, half the windows have a different mode from the window before.

With a 120-minute window, 30 minutes is 25% of the time; halve that and 12.5% of the data on each side is mislabeled. Treatment windows get only 87.5% of the 4 minutes, or 3.5, while control picks up 0.5 it did not earn. The measured difference is 3 minutes, a quarter short.

A 240-minute window does better, at 3.5 minutes; shrinking to 60 minutes leaves only 2. With 30-minute windows, you get 672 windows in 14 days instead of 168, but the measured reduction is 0. A 30-minute burn-in is no help there either, because it would discard all the data.

Cabify’s engineering blog points to the appeal of short windows: each window is one sample, so long windows force the experiment to run longer to reach statistical significance.

This simple model only pulls the estimate toward 0. In other models, carryover can push it the opposite way: in a synthetic-data example on freeCodeCamp, naive OLS gives 0.0688 when the true direct effect is 0.060.

Step 1: Set up the environment and the on/off schedule

You need Python 3, a basic grasp of linear regression and about an hour. The activation command below is for macOS and Linux.

python3 -m venv .venv
source .venv/bin/activate
pip install numpy pandas statsmodels

Create a file called switchback.py:

import numpy as np
import pandas as pd
import statsmodels.api as sm

CARRYOVER = 30  # minutes

def make_schedule(days, window, rng):
    n = days * 24 * 60 // window
    return rng.integers(0, 2, size=n)  # 1 = new mode

Check: with 14 days and 120-minute windows, the schedule must have 168 elements. Do not replace the random draw with strict alternation: each day has 12 windows, an even number, so peak hours would fall in the same mode for the full two weeks.

Step 2: Generate data with a known answer

The simulation is simplified: one order arrives every 2 minutes, demand varies by time of day, and each hour has a shared shock such as rain or traffic. Carryover lasts exactly 30 minutes; in practice it may fade gradually.

def simulate(schedule, window, rng, effect=-4.0, gap=2):
    assert window >= CARRYOVER, "window is shorter than the carryover"
    t = np.arange(0, len(schedule) * window, gap)
    win = t // window
    into = t % window
    treat = schedule[win]
    previous = schedule[np.maximum(win - 1, 0)]
    active = np.where(into < CARRYOVER, previous, treat)

    daily = 5 * np.sin(2 * np.pi * (t % 1440) / 1440)
    shock = rng.normal(0, 3, size=t[-1] // 60 + 1)[t // 60]
    noise = rng.normal(0, 6, size=len(t))
    y = 35 + daily + shock + effect * active + noise
    return pd.DataFrame(
        {"win": win, "into": into, "treat": treat, "y": y}
    )

The assert is there because the function looks back only one window. If the window were shorter than the carryover, the model would be wrong without raising an error. To try CARRYOVER = 60, keep every window at 60 minutes or more.

Check: 14 days should produce 10,080 rows. The treat column is the scheduled mode; the active variable inside the function is the mode that actually drives the outcome, which you never see in a client’s data.

Step 3: Cut the burn-in and cluster errors by window

Burn-in is the opening stretch of a window that is excluded from the analysis; Statsig also lets you exclude the closing stretch, called burn-out. Cabify uses the same approach, under the name washout, to remove the influence of the previous mode.

A study of switchbacks under geometric mixing finds that the standard design suffers considerable carryover bias, and that well-chosen burn-in improves it markedly. The same study notes that with a bias-corrected analysis, burn-in data does not always have to be discarded. This guide cuts the data because that is easier to explain to a client.

Cutting data deals only with bias. Orders in one window share the same mode and the same rain, so MetricGate’s documentation calls for clustered standard errors, and Statsig’s blog advises against the standard t-test used in A/B tests. The function below computes both kinds of error for comparison.

def analyse(df, burn_in=0):
    d = df[df["into"] >= burn_in]
    X = sm.add_constant(d["treat"].to_numpy(dtype=float))
    fit = sm.OLS(d["y"].to_numpy(), X).fit()
    robust = fit.get_robustcov_results(
        cov_type="cluster",
        groups=d["win"].to_numpy(),
        use_t=True,
        df_correction=True,
    )
    return (robust.params[1], fit.bse[1],
            robust.bse[1], robust.pvalues[1])

According to the statsmodels documentation, df_correction sets the degrees of freedom to the number of groups minus one, rather than basing them on the total number of observations. Each window is a group here, so 168 windows give 167 degrees of freedom even though you have 10,080 orders.

Step 4: Repeat 300 times to expose the bias

A single run can be off by chance. Only the average of 300 runs reveals a systematic error.

def run(days=14, window=120, burn_in=0,
        effect=-4.0, gap=2, reps=300, seed=7):
    rng = np.random.default_rng(seed)
    rows = []
    for _ in range(reps):
        schedule = make_schedule(days, window, rng)
        df = simulate(schedule, window, rng, effect, gap)
        rows.append(analyse(df, burn_in))
    out = pd.DataFrame(
        rows, columns=["effect", "se_plain", "se_cluster", "p"]
    )
    summary = out[["effect", "se_plain", "se_cluster"]].mean()
    summary["reject_rate"] = (out["p"] < 0.05).mean()
    return summary

if __name__ == "__main__":
    for b in [0, 10, 20, 30, 40]:
        print("burn-in", b)
        print(run(burn_in=b).round(2))

    print("Window of", CARRYOVER, "minutes, no burn-in")
    print(run(window=CARRYOVER).round(2))
python switchback.py

Check: with 120-minute windows, effect should track the figure at the top of this guide, with a negative sign: from about -3.0 with no burn-in to about -4.0 at 30 minutes and above. With 300 repetitions, a deviation of about 0.08 is normal.

Given the variances built into the simulation, se_plain should be around 0.15 with no burn-in and 0.17 at a burn-in of 30. The se_cluster column should be around 0.65 at both levels, nearly four times as large. If the two columns are almost equal, check the groups variable.

The last run, with a 30-minute window, should give an effect around 0: every order carries the previous mode’s result.

If the result keeps drifting as you increase burn-in, the carryover may not have run its course. Even so, fix the burn-in before looking at the official data, so nobody can pick the prettiest number.

Step 5: Do you have enough days to conclude anything?

Before promising anything to the client, add two tests to the end of the __main__ block:

    print("No effect")
    print(run(burn_in=30, effect=0.0))

    for days in [7, 14, 28]:
        print(days, "days")
        print(run(days=days, burn_in=30, effect=-1.0))

Check: in the no-effect scenario, reject_rate should fall between 0.03 and 0.08; anything much higher signals false alarms. In the loop that follows, reject_rate is the power to detect a 1-minute reduction.

Calculated from the theoretical error, 7, 14 and 28 days give power of about 0.18, 0.33 and 0.57; with 300 repetitions, a difference of 0.05 is common. If your threshold is 80%, all three fail: you need to renegotiate the duration or the smallest effect worth detecting, or analyze the data more cleverly.

More orders barely help

The table below breaks down the variance of the mean of a 120-minute window. Doubling the orders touches only the smallest row; try gap=1 to see for yourself.

Source of variation Calculation 60 orders 120 orders
Time of day 25 divided by 2 12.5 12.5
Hourly shock 9 divided by 2 4.5 4.5
Per-order noise 36 divided by number of orders 0.6 0.3
Total 17.6 17.3

A June 2026 paper, “Powerful Switchback Experiments – Or Not?”, points the same way: as more data is packed into existing cells, the gains shrink quickly. Its formula also shows that when clusters are uneven in size, power is capped at a level set by that very imbalance.

The simulation here gives every window the same number of orders, so it does not account for this. If the client’s peak windows hold far more orders than the overnight ones, true power may be lower than the figure you just computed. Count orders per window before promising a number of days.

Two ways to buy more power

Keeping 120-minute windows and doubling the number of days cuts the variance of the estimate by about half. A cheaper option is to let the regression absorb the 12.5, since it repeats every day. In analyse, replace the X line with the snippet below; it applies only to 120-minute windows, where each day has 12 slots.

    slot = pd.get_dummies(d["win"] % 12, drop_first=True)
    X = np.column_stack([
        np.ones(len(d)),
        d["treat"].to_numpy(dtype=float),
        slot.to_numpy(dtype=float),
    ])

Check: with 14 days and a burn-in of 30, se_cluster should fall from about 0.66 to below 0.4, and power for a 1-minute reduction should rise to about 0.75. Rerun the no-effect scenario before using it, because adding variables with few windows can increase false alarms.

Having few clusters is a real risk: in the simulation study cited at the start, with ten clusters or fewer, the confidence intervals of all four methods contained the true effect only about 82% of the time.

The three likeliest failures

The first mistake is copying someone else’s configuration. The example in the cluster-experiments documentation uses 4-hour windows and a fixed 30-minute washover; treat that as a starting point, because carryover at your client may last longer.

The next is lifting a research formula out of its assumptions. Bojinov, Simchi-Levi and Zhao recommend making each period about as long as the order of carryover, but within their own design framework and assumptions. Take a raw difference in means over 30-minute windows and, as you have just seen, you measure 0.

The last concerns logging: recording the scheduled mode when the system switched late or someone turned it off by hand. Store the actual switch time, and assign orders by when they were created. If orders often spill into the next window, consider adding burn-out at the end.

At the client, the first question goes to operations

The length of the carryover is not written in the code. So start by asking whoever runs dispatch: “After you change how orders are assigned, how long before everything settles down?”

Then send them one page covering the primary metric, window, burn-in, number of days, hours when switching is forbidden, and who has the authority to stop. Run the on/off schedule for a few days with two identical modes to test the logs and the process.

If you are job hunting, watch for “experimentation”, “causal inference”, “measure impact” or “marketplace” in postings. An honest CV line might read: “Built a switchback simulator, quantified carryover bias, and chose window length and run time with power analysis”, with a link to the repo.

When a client asks why the first 30 minutes of every window must go, show them the results you ran yourself: keep those 30 minutes, and a 4-minute improvement shrinks to 3.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
11 sources
Read next on the roadmap · Stage 6: MeasurementWhen PM4Py blames the wrong bottleneckOne missing column makes the library count work as waiting without raising an error; 16 rows of data are enough to expose the mistake and fix it.