Implement the Lan-DeMets Pocock-type alpha-spending function

Quick Overview

Implement the Lan-DeMets Pocock-type alpha-spending function in Python, returning the cumulative type I error spent at each interim look of a group sequential test. It tests vectorized NumPy code, floating-point care at the final look, and how Pocock and O'Brien-Fleming designs differ.

Implement the Lan-DeMets Pocock-type alpha-spending function

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `pocock_alpha_spent` in `solution.py`: ```python def pocock_alpha_spent(t: np.ndarray, alpha: float = 0.05) -> np.ndarray: ``` Given a 1-D array `t` of information fractions in (0, 1], monotone increasing and ending at `1.0`, return the cumulative type I error spent at each look under the Lan-DeMets Pocock-type spending function `alpha_spent(t) = alpha * ln(1 + (e - 1) * t)`, with `e = math.e` and `ln = np.log`. Requirements: - Return cumulative alpha spent, not incremental per-look alpha. - The output has the same length as `t`. - Spend exactly `alpha` at `t = 1.0`. - Return raw, unrounded floats. Example: ```python pocock_alpha_spent(np.array([0.25, 0.5, 0.75, 1.0])) # -> [0.017868700975, 0.031005725348, 0.041399446962, 0.05] ``` ```hint Check the endpoint Evaluate the formula at `t = 1.0` by hand, then ask whether the floating-point result is guaranteed to match it. ``` ### Constraints & Assumptions - `t` is a 1-D array (or array-like) of strictly increasing values in (0, 1], and its last element is `1.0`. - `alpha` is the overall significance level, a float in (0, 1) with default 0.05. ### What a Strong Answer Covers - A vectorized evaluation of the formula with the natural log, giving one cumulative value per look. - Why the formula spends exactly `alpha` at `t = 1.0`, and whether floating point keeps that exact. - The difference between cumulative spend and the per-look increments. - How the Pocock-type curve compares with O'Brien-Fleming and what that means for early stopping. ### Follow-up Questions - How would you derive the incremental alpha spent at each look? - How does the Pocock-type function differ from the O'Brien-Fleming-type spending function? - For a product A/B test with weekly peeks, how would you choose between the two?

Overview: Implement the Lan-DeMets Pocock-type alpha-spending function in Python, returning the cumulative type I error spent at each interim look of a group sequential test. It tests vectorized NumPy code, floating-point care at the final look, and how Pocock and O'Brien-Fleming designs differ.

General logo
General
Nov 25, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement pocock_alpha_spent in solution.py:

def pocock_alpha_spent(t: np.ndarray, alpha: float = 0.05) -> np.ndarray:

Given a 1-D array t of information fractions in (0, 1], monotone increasing and ending at 1.0, return the cumulative type I error spent at each look under the Lan-DeMets Pocock-type spending function alpha_spent(t) = alpha * ln(1 + (e - 1) * t), with e = math.e and ln = np.log.

Requirements:

  • Return cumulative alpha spent, not incremental per-look alpha.
  • The output has the same length as t .
  • Spend exactly alpha at t = 1.0 .
  • Return raw, unrounded floats.

Example:

pocock_alpha_spent(np.array([0.25, 0.5, 0.75, 1.0]))
# -> [0.017868700975, 0.031005725348, 0.041399446962, 0.05]

Constraints & Assumptions

  • t is a 1-D array (or array-like) of strictly increasing values in (0, 1], and its last element is 1.0 .
  • alpha is the overall significance level, a float in (0, 1) with default 0.05.

What a Strong Answer Covers Guidance

  • A vectorized evaluation of the formula with the natural log, giving one cumulative value per look.
  • Why the formula spends exactly alpha at t = 1.0 , and whether floating point keeps that exact.
  • The difference between cumulative spend and the per-look increments.
  • How the Pocock-type curve compares with O'Brien-Fleming and what that means for early stopping.

Follow-up Questions Guidance

  • How would you derive the incremental alpha spent at each look?
  • How does the Pocock-type function differ from the O'Brien-Fleming-type spending function?
  • For a product A/B test with weekly peeks, how would you choose between the two?