PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches
|Home/Statistics & Math/Roblox

Implement robust one/two-sided p-value function

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in statistical hypothesis testing, numerical computing, and numerical stability when implementing p-value calculations for z and t distributions, and it targets the Statistics & Math domain for a data scientist role.

  • hard
  • Roblox
  • Statistics & Math
  • Data Scientist

Implement robust one/two-sided p-value function

Company: Roblox

Role: Data Scientist

Category: Statistics & Math

Difficulty: hard

Interview Round: Technical Screen

Implement in Python a function p_value(stat, alternative, dist, df=None) that returns the p-value for one-sided and two-sided tests. Requirements: (1) alternative ∈ {'less','greater','two-sided'}; (2) dist ∈ {'z','t'} where 'z' uses the standard normal and 't' uses Student's t with degrees of freedom df; (3) for 'z', do not use external libraries—implement the CDF via math.erf/erfc to achieve at least 1e-9 relative error for |z| ≤ 8 and use numerically stable tails; (4) for 't', you may use scipy.stats.t.cdf if available, otherwise implement a reasonable approximation (e.g., incomplete beta/continued fraction) and document error bounds; (5) handle edge cases: NaN/inf inputs, df<1, and extreme |stat|; (6) include minimal unit tests: z=0 two-sided→1.0; z=1.96 two-sided≈0.0500; z=5 greater≈2.87e-7; t=2.0 with df=10 two-sided≈0.070; monotonicity checks; (7) explain how you ensure numerical stability for very small p-values.

Quick Answer: This question evaluates proficiency in statistical hypothesis testing, numerical computing, and numerical stability when implementing p-value calculations for z and t distributions, and it targets the Statistics & Math domain for a data scientist role.

Related Interview Questions

  • Apply Bayes' rule to compute posterior - Roblox (hard)
  • Compute sample size and Bayes posterior - Roblox (hard)
  • Derive variance and CTR confidence intervals - Roblox (medium)
  • Compute GSP vs VCG payments with reserves - Roblox (medium)
  • Compute A/B test sample size and Bayes posterior - Roblox (easy)
Roblox logo
Roblox
Oct 13, 2025, 9:49 PM
Data Scientist
Technical Screen
Statistics & Math
5
0

Implement p_value(stat, alternative, dist, df=None)

Context: You're building a small, production-quality helper to compute p-values for common one- and two-sided hypothesis tests. The function must be numerically stable in the tails and handle edge cases cleanly.

Requirements

  1. Signature and options
    • Implement in Python: p_value(stat, alternative, dist, df=None) .
    • alternative ∈ {'less', 'greater', 'two-sided'}.
    • dist ∈ {'z', 't'}.
  2. Distributions
    • 'z': Use the standard normal distribution. Do not use external libraries. Implement the CDF via math.erf/erfc with at least 1e-9 relative error for |z| ≤ 8, and use numerically stable tails.
    • 't': Use Student's t with df degrees of freedom. You may use scipy.stats.t.cdf (and sf ) if available. Otherwise, implement a reasonable approximation (e.g., via the regularized incomplete beta using a continued fraction), and document error bounds.
  3. Edge cases
    • Handle NaN/inf inputs.
    • For t-tests, reject invalid df (e.g., df < 1 ).
    • Handle extreme |stat| without catastrophic cancellation.
  4. Tests (minimal)
    • z=0, two-sided → 1.0
    • z=1.96, two-sided ≈ 0.0500
    • z=5, greater ≈ 2.87e-7
    • t=2.0 with df=10, two-sided ≈ 0.070
    • Monotonicity checks: for 'greater' p-value decreases as stat increases; two-sided p-value decreases as |stat| increases.
  5. Explain briefly how your implementation is numerically stable for very small p-values.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Statistics & Math•More Roblox•More Data Scientist•Roblox Data Scientist•Roblox Statistics & Math•Data Scientist Statistics & Math
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.