Implement the Lan-DeMets O'Brien-Fleming alpha-spending function

Quick Overview

Implement the Lan-DeMets O'Brien-Fleming alpha-spending function in Python, returning the cumulative type I error spent at each interim look of a group sequential test. It tests NumPy vectorization, precision when computing small normal tail probabilities, and how sequential designs control false positives.

Implement the Lan-DeMets O'Brien-Fleming alpha-spending function

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `obf_alpha_spent` in `solution.py`: ```python def obf_alpha_spent(t: np.ndarray, alpha: float = 0.05) -> np.ndarray: ``` The input `t` holds the information fractions of the planned looks in a group sequential test. The values are increasing, lie in (0, 1], and end at `1.0`. Return the cumulative alpha spent at each look under the Lan-DeMets O'Brien-Fleming spending function: ```python 2 * norm.sf(norm.ppf(1 - alpha / 2) / sqrt(t)) ``` Requirements: - Use `norm.sf` from `scipy.stats`, not `1 - norm.cdf`. - Spend exactly `alpha` at `t = 1.0`. - Return raw floats, with no rounding. Example: ```python obf_alpha_spent(np.array([0.25, 0.5, 0.75, 1.0])) # -> [8.857543832140e-05, 5.574596680784e-03, 2.362512131760e-02, 0.05] ``` ```hint Small information fractions Work out how large `z / sqrt(t)` gets at `t = 0.01`, and how close `norm.cdf` of that value is to 1 in double precision. ``` ```hint The last look Check whether a round trip through `norm.ppf` and then `norm.sf` gives back `alpha / 2` to the last bit. ``` ### 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 two-sided significance level, a float in (0, 1) with default 0.05. - The output has the same shape as `t`. ### What a Strong Answer Covers - A vectorized implementation that computes the critical value once and applies the formula to the whole array. - Why `norm.sf` keeps its precision at small `t`, and what `1 - norm.cdf` returns there. - How the function meets the exact-alpha requirement at `t = 1.0` in floating point. - What the cumulative curve says about how strict the early looks are. - Behavior on edge inputs: a plain list, a scalar, `t` near 0, or values outside the contract. ### Follow-up Questions - How does the Pocock spending function differ, and how would you implement it? - How would you convert cumulative spend into per-look nominal significance boundaries? - What changes if the interim looks happen at different information fractions than planned?

Overview: Implement the Lan-DeMets O'Brien-Fleming alpha-spending function in Python, returning the cumulative type I error spent at each interim look of a group sequential test. It tests NumPy vectorization, precision when computing small normal tail probabilities, and how sequential designs control false positives.

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

Implement obf_alpha_spent in solution.py:

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

The input t holds the information fractions of the planned looks in a group sequential test. The values are increasing, lie in (0, 1], and end at 1.0. Return the cumulative alpha spent at each look under the Lan-DeMets O'Brien-Fleming spending function:

2 * norm.sf(norm.ppf(1 - alpha / 2) / sqrt(t))

Requirements:

  • Use norm.sf from scipy.stats , not 1 - norm.cdf .
  • Spend exactly alpha at t = 1.0 .
  • Return raw floats, with no rounding.

Example:

obf_alpha_spent(np.array([0.25, 0.5, 0.75, 1.0]))
# -> [8.857543832140e-05, 5.574596680784e-03, 2.362512131760e-02, 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 two-sided significance level, a float in (0, 1) with default 0.05.
  • The output has the same shape as t .

What a Strong Answer Covers Guidance

  • A vectorized implementation that computes the critical value once and applies the formula to the whole array.
  • Why norm.sf keeps its precision at small t , and what 1 - norm.cdf returns there.
  • How the function meets the exact-alpha requirement at t = 1.0 in floating point.
  • What the cumulative curve says about how strict the early looks are.
  • Behavior on edge inputs: a plain list, a scalar, t near 0, or values outside the contract.

Follow-up Questions Guidance

  • How does the Pocock spending function differ, and how would you implement it?
  • How would you convert cumulative spend into per-look nominal significance boundaries?
  • What changes if the interim looks happen at different information fractions than planned?