Implement Python Function for Statistical Test P-Values
RobloxData Scientist · Technical ScreenLast updated
This question evaluates proficiency in statistical hypothesis testing, p-value interpretation, and implementing distribution-based calculations (Z and Student-t) in code, and it falls under the Coding & Algorithms domain for data scientist roles.
Scenario
You need a utility that calculates p-values for one-sided and two-sided statistical tests.
Question
Write a Python function compute_p_value(stat, dist='z', df=None, alternative='two-sided') that returns the p-value. Your code should support Z-tests and Student-t tests, and handle 'less', 'greater', and 'two-sided' alternatives.
Hints
Use the CDF of the chosen distribution; for two-sided tests return 2*min(CDF, 1-CDF). Libraries like scipy.stats are allowed.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.