Alpha-Spending Nominal Z-Boundaries for K Interim Looks

Quick Overview

Implement a Python function that converts an O'Brien-Fleming-type or Pocock-type alpha-spending function into nominal two-sided z cutoffs for K equally spaced interim looks. It tests group sequential testing, how cumulative type I error is split across looks, two-sided normal quantiles, and why this approximation is conservative.

Alpha-Spending Nominal Z-Boundaries for K Interim Looks

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: hard

Interview Round: Other

Implement `spending_nominal_boundaries(kind: str, K: int, alpha: float = 0.05) -> np.ndarray` in `solution.py`. For `K` equally spaced looks at an experiment, return the length-`K` array of conservative nominal two-sided z-boundaries implied by an alpha-spending function. This is a deliberate approximation. The exact Lan-DeMets boundaries, which come from the multivariate normal distribution of the test statistics, are not required. The function must follow these steps: - Information fractions: `t = np.arange(1, K+1)/K`, ending at `1.0`. - `kind == 'obf'` (O'Brien-Fleming-type spending): `cum = 2*norm.sf(norm.ppf(1-alpha/2)/np.sqrt(t))`. - `kind == 'pocock'` (Pocock-type spending): `cum = alpha*np.log(1+(np.e-1)*t)`. - Incremental spend: `incr = np.diff(cum, prepend=0.0)`. - Return `norm.ppf(1 - incr/2)` as raw floats. Expected output for four looks: ```python spending_nominal_boundaries('obf', 4) # -> [3.919927969080, 2.777017575309, 2.364580076999, 2.220647016436] spending_nominal_boundaries('pocock', 4) # -> [2.368327703524, 2.480032945984, 2.562447781404, 2.627536832442] ``` ```hint Cumulative versus per-look spend The spending function reports the total error used up to each look. Work out how much of it is new at each look before you convert anything to a z-value. ``` ```hint Check the first look Nothing is spent before look 1, so the first OBF cutoff has a closed form. Compute it by hand and compare it with your output. ``` ```hint Two tails A two-sided cutoff splits its tail probability between both tails. Watch which quantile you ask `norm.ppf` for. ``` ### Constraints & Assumptions - `K` is a positive integer and the looks are equally spaced in information. - `alpha` is the total two-sided type I error, 0.05 by default. - `kind` is either `'obf'` or `'pocock'`. - `numpy` and `scipy.stats.norm` are available, and the values are returned unrounded. ### What a Strong Answer Covers - Building the information-fraction grid and evaluating both spending functions so the cumulative spend reaches `alpha` at the final look. - Turning cumulative spend into per-look increments and confirming they sum to `alpha`. - Mapping each increment to a two-sided quantile and reproducing both example arrays. - A clear argument for why these nominal cutoffs are conservative relative to exact boundaries. - Handling an unknown `kind` and the numerical behavior of very small increments. ### Follow-up Questions - Why are these cutoffs conservative compared with exact Lan-DeMets boundaries, and what would you compute to get the exact ones? - How would you extend the function to unequally spaced information fractions? - How do the OBF-type and Pocock-type designs differ in the chance of stopping early and in what they cost at the final analysis?

Overview: Implement a Python function that converts an O'Brien-Fleming-type or Pocock-type alpha-spending function into nominal two-sided z cutoffs for K equally spaced interim looks. It tests group sequential testing, how cumulative type I error is split across looks, two-sided normal quantiles, and why this approximation is conservative.

Nov 24, 2026
hardData ScientistOtherAnalytics & Experimentation
0
0

Implement spending_nominal_boundaries(kind: str, K: int, alpha: float = 0.05) -> np.ndarray in solution.py. For K equally spaced looks at an experiment, return the length-K array of conservative nominal two-sided z-boundaries implied by an alpha-spending function. This is a deliberate approximation. The exact Lan-DeMets boundaries, which come from the multivariate normal distribution of the test statistics, are not required.

The function must follow these steps:

  • Information fractions: t = np.arange(1, K+1)/K , ending at 1.0 .
  • kind == 'obf' (O'Brien-Fleming-type spending): cum = 2*norm.sf(norm.ppf(1-alpha/2)/np.sqrt(t)) .
  • kind == 'pocock' (Pocock-type spending): cum = alpha*np.log(1+(np.e-1)*t) .
  • Incremental spend: incr = np.diff(cum, prepend=0.0) .
  • Return norm.ppf(1 - incr/2) as raw floats.

Expected output for four looks:

spending_nominal_boundaries('obf', 4)
# -> [3.919927969080, 2.777017575309, 2.364580076999, 2.220647016436]

spending_nominal_boundaries('pocock', 4)
# -> [2.368327703524, 2.480032945984, 2.562447781404, 2.627536832442]

Constraints & Assumptions

  • K is a positive integer and the looks are equally spaced in information.
  • alpha is the total two-sided type I error, 0.05 by default.
  • kind is either 'obf' or 'pocock' .
  • numpy and scipy.stats.norm are available, and the values are returned unrounded.

What a Strong Answer Covers Guidance

  • Building the information-fraction grid and evaluating both spending functions so the cumulative spend reaches alpha at the final look.
  • Turning cumulative spend into per-look increments and confirming they sum to alpha .
  • Mapping each increment to a two-sided quantile and reproducing both example arrays.
  • A clear argument for why these nominal cutoffs are conservative relative to exact boundaries.
  • Handling an unknown kind and the numerical behavior of very small increments.

Follow-up Questions Guidance

  • Why are these cutoffs conservative compared with exact Lan-DeMets boundaries, and what would you compute to get the exact ones?
  • How would you extend the function to unequally spaced information fractions?
  • How do the OBF-type and Pocock-type designs differ in the chance of stopping early and in what they cost at the final analysis?