1/17
Learn
t-tests and p-values, the way the statistics round asks
A Netflix data science candidate had to compute a t statistic in the statistics round (1 report), and an OpenAI round asked how you would explain a p-value (1 report). This lesson's practice problem puts both in code, with only the standard library, in three levels:
one_sample_t(xs, mu0)andwelch_t(xs, ys): each t statistic, and its degrees of freedom.paired_t(xs, ys)on the differences, andt_p_value(t, df): the two-sided p-value from Student's t curve.permutation_p(xs, ys, reps, seed), thenbonferroni,holmandbenjamini_hochberg, each returning the indices of the p-values it rejects.
Call Returns the t for 16 deliveries averaging 4.6 days, with a standard deviation of 0.8, against a promised 4.0 t = 3.0, with 15 degrees of freedom t_p_value(3.0, 15)0.0090 paired_t([5, 7, 6, 9], [4, 5, 5, 6])t = 3.66, with 3 degrees of freedom benjamini_hochberg([0.002, 0.02, 0.04, 0.3], 0.05)[0, 1]Then tell me what a p-value is, and what it isn't.
The lesson builds each piece on one running example, a shop's delivery carriers: t against z, Welch's test, pairs, what a p-value says, a permutation test, and three corrections for many tests. Six steps end with a small task in the editor. It builds on the distributions lesson and its central limit theorem.