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.
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.
p_value(stat, alternative, dist, df=None)
.
alternative
∈ {'less', 'greater', 'two-sided'}.
dist
∈ {'z', 't'}.
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.
df
(e.g.,
df < 1
).
Login required