KatInterview

Evaluating a Dispatch Change: Welch Test on Pickup Wait Times

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentswelch-t-testpandasab-testing

Last updated

Compute a Welch's t-test p-value on pickup wait times for one city and month, then judge whether the result is trustworthy and propose a sounder experiment for a shared fleet.

A ride-hailing company tested a new dispatch (routing) algorithm meant to shorten pickup wait, the time between a rider's request and the vehicle arriving. The test ran in one city (San Francisco) during July 2024, and users were assigned to a control or treatment variant.

You have two pandas DataFrames:

  • df_users: user_id, variant
  • df_rides: ride_id, ride_date, city, time_to_pickup

Assume df_rides also contains user_id (needed for the join) and that San Francisco appears under a single label such as "SF". Verify both before relying on them.

Clarify first. State your assumptions on: the variant labels and whether each user has exactly one variant; one-sided vs two-sided testing; the significance level; how to treat rides with a missing time_to_pickup; and whether ride_date is a date or a timestamp and in which time zone "July" is defined.

Part 1: compute the p-value. Write a Python function that:

  1. keeps only San Francisco rides from the whole of July 2024,
  2. attaches each ride's rider variant,
  3. runs Welch's t-test on time_to_pickup between the two variants,
  4. returns the p-value.

Cover the pitfalls: date parsing with an exclusive upper boundary, a join that neither duplicates nor drops rides silently, users who appear in more than one variant, missing values, and what the test statistic and degrees of freedom are.

Part 2: validity. Interpret the result. Is it significant at your chosen level? Can the team conclude the new algorithm reduces pickup wait? If not, design a better experiment, including metrics, duration, power and the analysis plan.

Hints

Hint 1

Use a half-open date range (on or after 1 July, strictly before 1 August) so that timestamps on 31 July are not lost, and check the join with a validation option and a count of rides lost.

Hint 2

Welch's test does not pool variances: the statistic is the difference in means divided by sqrt(s1^2/n1 + s2^2/n2), and the degrees of freedom come from the Welch-Satterthwaite formula. In SciPy this is ttest_ind with equal_var=False.

Hint 3

Ask who shares the supply: if both variants draw on the same drivers, one arm's behavior changes the other arm's wait times, so the arms are not independent. Think about randomizing time blocks or regions instead of riders.

Hint 4

Also notice that the randomization unit is the user but the analysis unit is the ride, so repeated rides by the same user are correlated and the naive standard error is too small.