KatInterview

Did a New Dispatch Algorithm Cut Rider Wait Times? A/B Analysis

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentsab-testingwelch-t-testpandas

Last updated

Analyze a city-level dispatch A/B test in pandas, run a Welch t-test on wait time, and discuss clustering, selection bias, effect size, and a stronger experiment design.

A ride-hailing team ran an experiment during July 2024 in a single city (San Francisco) to check whether a new dispatch algorithm shortens the time riders wait to be picked up. You are given two tables:

df_users(user_id, variant)
df_rides(ride_id, user_id, ride_date, city, time_to_pickup)

Assumptions

  • Use Python with pandas and a standard statistics library such as scipy or statsmodels.
  • Only rides in San Francisco from July 1 through July 31, 2024 (inclusive of the whole last day) are in scope.
  • The requested test is a two-sided Welch's t-test on time_to_pickup between the two variants.
  • If a user can appear in many rides, you must state what that does to the test's independence assumption.

Questions you would want answered before starting

  • Was the treatment randomized per user, and is each user assigned exactly once and permanently?
  • Which variant is the control? Are any assignments missing or duplicated?
  • Is ride_date timezone-aware? Are canceled or invalid rides already removed?
  • What significance level and what minimum practically meaningful improvement were set before looking at the data?

Part 1: Compute the p-value

Filter the rides, attach each ride's user variant, run Welch's t-test on time_to_pickup, and return the p-value. Describe the data-quality checks you would run along the way, and report group sizes and means next to the p-value.

Part 2: Interpret and strengthen the experiment

Explain when the result counts as statistically significant and whether significance alone shows the new algorithm is better. Then propose a more robust experiment and analysis plan.

Hints

Hint 1

For the date filter, use a half-open interval (`>= 2024-07-01` and `< 2024-08-01`) so rides late on July 31 are not dropped, and confirm the timezone before comparing.

Hint 2

Validate the join: assert that `user_id` is unique in `df_users`, check for rides whose user has no variant, and pass `equal_var=False` to get Welch rather than Student's test.

Hint 3

Think about the unit of randomization versus the unit of analysis. If users were randomized but you test rides, repeated rides from one user are correlated, so aggregate per user or use cluster-robust standard errors.

Hint 4

A small p-value says the difference is unlikely under the null, not that it is large or valuable. Report the difference in means with a confidence interval and compare it to a pre-set minimum effect.