5.4.14 · D3Scientific Computing (Python)

Worked examples — scipy.stats — distributions, hypothesis tests

2,720 words12 min readBack to topic

The scenario matrix

Every question this topic throws at you falls into one of these cells. The worked examples below each carry a [cell] tag so you can see the whole grid gets covered.

# Case class What makes it distinct Covered by
A Left tail.cdf want , area to the left Ex 1
B Right tail.sf want , upper tail Ex 2
C Middle band — cdf minus cdf want Ex 3
D Inverse / quantile.ppf given probability, find the cutoff value Ex 4
E Degenerate: zero effect , so , Ex 5
F Two-sample difference clear gap → tiny Ex 6
G Categorical counts — chi-square discrete faces, not a continuous Ex 7
H Boundary probabilities and give Ex 8
I Word problem + one-sided translate English → , pick tail Ex 9
J Exam twist: non-normal scale expon where scale = 1/λ, not λ Ex 10

We use the standard normal picture repeatedly, so pin it down first.

Figure — scipy.stats — distributions, hypothesis tests

Prerequisites worth a glance: Normal Distribution, p-values and Significance, Chi-square Distribution, Maximum Likelihood Estimation.


Worked examples


Recall Quick self-quiz over the matrix

Which method for ? ::: .cdf, i.e. Which method for ? ::: .sf, i.e. Given a percentile, find the value? ::: .ppf, i.e. What is a z-score? ::: — how many spreads the value is from centre norm.ppf(0) equals? ::: For expon, scale equals? ::: , not Chi-square statistic formula? ::: Why divide by for ? ::: one degree of freedom is spent computing , leaving ; it de-biases the estimate ttest_ind default assumption? ::: equal_var=True (pooled); use equal_var=False for Welch when spreads differ