Measuring Treatment Effect from Experiment and Event Data
Statistics & ExperimentsModel answerLast updated
Define a user-level outcome from experiment assignment and event logs, then estimate the average treatment effect with a confidence interval.
You have two data sources:
- Assignment log: Each row contains a user identifier, the timestamp when they entered the experiment, and whether they were assigned to treatment or control.
- Event log: Each row contains a user identifier, a timestamp, and a measured value (for example, session duration, revenue, or engagement score).
Your task is to estimate the causal effect of the treatment. Specifically:
- Define a user-level outcome metric derived from the event log.
- Explain how you would construct the analysis dataset by joining these sources.
- Describe how to estimate the treatment effect as a difference in means and construct a confidence interval.
- Explain the relationship between the confidence interval and a hypothesis test for the treatment effect.
This is a conceptual and statistical design question. You are not required to write queries, but you should be explicit about metric definitions, time windows, handling of missing data, and inference assumptions.
Hints
Hint 1
Define the outcome relative to each user's entry time, not using absolute calendar dates, so treatment and control are comparable.
Hint 2
Aggregation should happen at the user level—one row per user—before computing the difference in means.
Hint 3
A 95% confidence interval that excludes zero corresponds to rejecting the null hypothesis at the 5% significance level.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Defining the User-Level Outcome
The metric must be computed over a fixed observation window measured from each user's entry time, not calendar time. For example, define the outcome as total revenue (or session count, or total minutes) in the 14 days following assignment. This ensures that users who enter the experiment at different dates are measured over comparable periods.
State the metric explicitly:
Outcome = sum of event values occurring between assignment time and assignment time + 14 days, for each user.
If a user has no events in that window, assign outcome = 0 (assuming the metric is naturally zero when there is no activity). If missingness has a different meaning (for example, the user churned), document that assumption.
Constructing the Analysis Dataset
- Filter events to the observation window: For each user in the assignment log, keep only events whose timestamp falls within [assignment_time, assignment_time + 14 days].
- Aggregate to user level: Group by user and sum (or average, or count) the event values. The result is one row per user with
user_id,treatment_group, andoutcome. - Include users with zero events: Left join the assignment log to the aggregated events so that users with no events are retained with outcome = 0.
- Validate the cohort: Check that assignment is roughly balanced (50/50 split if it's a simple A/B test) and that there are no systematic differences in entry time or baseline covariates between treatment and control.
Estimating the Treatment Effect
Compute the difference in sample means:
[ \hat{\tau} = \bar{Y}{\text{treatment}} - \bar{Y}{\text{control}} ]
where (\bar{Y}{\text{treatment}}) is the average outcome among treated users and (\bar{Y}{\text{control}}) is the average among control users.
Construct a 95% confidence interval using the standard error of the difference:
[ SE(\hat{\tau}) = \sqrt{\frac{s^2_{\text{treatment}}}{n_{\text{treatment}}} + \frac{s^2_{\text{control}}}{n_{\text{control}}}} ]
where (s^2) is the sample variance and (n) is the sample size in each group. The confidence interval is:
[ \hat{\tau} \pm 1.96 \cdot SE(\hat{\tau}) ]
This assumes the sample is large enough for the Central Limit Theorem to apply. For small samples or highly skewed metrics, consider bootstrap or permutation-based intervals.
Relationship to Hypothesis Testing
A two-sided hypothesis test of (H_0: \tau = 0) versus (H_A: \tau \neq 0) at the 5% significance level rejects the null if and only if the 95% confidence interval does not contain zero.
- If the interval is entirely above zero, the treatment has a statistically significant positive effect.
- If the interval contains zero, we fail to reject the null; the data are consistent with no effect.
- The p-value is the probability of observing a difference as extreme as (\hat{\tau}) under the null, and (p < 0.05) corresponds to the interval excluding zero.
Key Assumptions and Checks
- Randomization: Users are randomly assigned to treatment or control, so the groups are comparable at baseline. Check balance on observable covariates.
- No interference: One user's treatment does not affect another's outcome (SUTVA). Violations occur in network or marketplace settings.
- Complete follow-up: All users have the opportunity to generate events for the full 14 days. If some users enter near the end of the experiment and are censored, restrict analysis to users with complete follow-up.
- Independent observations: The unit of randomization is the user, and outcomes are independent across users. If users are clustered (for example, by household or device), use clustered standard errors.
Common Mistakes
- Using event-level data: Computing a difference in means at the row level (one row per event) inflates the sample size artificially and underestimates standard errors. Always aggregate to the randomization unit first.
- Ignoring time windows: Comparing users who entered on different days without aligning their observation windows introduces bias if the metric has trends or seasonality.
- Dropping users with zero outcomes: Excluding inactive users biases the estimate; missing events should typically be treated as zero activity.
- Misinterpreting the confidence interval: A wide interval that includes zero does not mean "no effect"; it means the data are too noisy to detect an effect of this size. Power calculations should be done in advance.
Extensions
- Variance reduction: Include baseline covariates (for example, pre-experiment activity) using regression adjustment or CUPED to shrink the confidence interval.
- Multiple testing: If running many experiments or metrics simultaneously, adjust significance thresholds (Bonferroni, FDR) to control the family-wise error rate.
- Heterogeneous effects: Estimate treatment effects within subgroups (for example, new versus returning users) but pre-specify these analyses to avoid p-hacking.