5.4.14 · D5Scientific Computing (Python)

Question bank — scipy.stats — distributions, hypothesis tests

2,098 words10 min readBack to topic

Parent: scipy.stats — distributions, hypothesis tests · builds on Normal Distribution, p-values and Significance, Central Limit Theorem, Chi-square Distribution, Maximum Likelihood Estimation.


The vocabulary these traps use (define before you answer)

Before the questions, pin down every symbol and function name so nothing below is a mystery. Look at the picture: it is ONE bell curve with the four functions all drawn on it.

Figure — scipy.stats — distributions, hypothesis tests

The next figure shows the CDF/SF trade-off directly: as moves right, yellow (left area) grows toward and red (right area) shrinks toward — they are two views of the same split.

Figure — scipy.stats — distributions, hypothesis tests

The two-sided doubling of a tail is what makes a two-sided p-value; here it is drawn as both red tails of one curve.

Figure — scipy.stats — distributions, hypothesis tests

And this last figure shows the far-tail precision trap: why 1 - cdf collapses to zero while .sf keeps every digit.

Figure — scipy.stats — distributions, hypothesis tests

True or false — justify

A small p-value means the null hypothesis is probably false.
False — the p-value is , the reverse conditioning of ; it says the data is surprising assuming , not that is unlikely. See p-values and Significance.
A p-value of proves the two groups have equal means.
False — failing to reject is "no evidence of a difference," which can also happen with a tiny, low-power sample; absence of evidence is not evidence of absence.
For any distribution in scipy, loc is the mean and scale is the standard deviation.
False — that coincidence holds only for norm; in general loc shifts and scale stretches, e.g. for expon the mean equals scale , not the sd formula you'd expect.
stats.norm.pdf(0) returns a probability.
False — the PDF returns a density (height of the bell in figure s01), not a probability; probability comes from area, so a single point has probability zero for a continuous variable.
.sf(x) and 1 - .cdf(x) always give identical numbers.
False as stated — they are mathematically equal but not numerically identical: far in the tail 1 - cdf subtracts two near-1 floats and loses precision (see figure s04), while .sf is computed directly and stays accurate.
A larger sample makes every true (nonzero) effect show up as statistically significant eventually.
True — the standard error shrinks like , so with enough data any real nonzero difference will eventually cross ; the catch is that statistical significance then no longer implies the effect is large or important.
The t-statistic follows a normal distribution when is small.
False — because is estimated by , the extra uncertainty gives heavier tails, so follows Student- with degrees of freedom; it only approaches normal as grows.
Rejecting at means there's a 5% chance you're wrong.
False — is the false-positive rate when is actually true (a long-run property of the test), not the probability that this particular decision is a mistake.
The chi-square statistic can be negative.
False — every term is a squared difference divided by a positive expected count, so the sum is always ; it hits zero only when observed exactly equals expected. See Chi-square Distribution.
stats.norm.fit(sample) gives the true and of the population.
False — it returns maximum-likelihood estimates from the sample, which recover the truth only approximately and get better as the sample grows. See Maximum Likelihood Estimation.

Spot the error

p = stats.norm(100, 15).cdf(130) to find the fraction scoring above 130. Why is this wrong?
.cdf(130) gives the area to the left (fraction below, the yellow region in figure s02); for "above" you need the upper tail .sf(130) , the red region.
stats.expon(scale=0.5) was written to model events arriving at rate . Where's the trap?
For expon, scale , so scale=0.5 means ; to get you'd write scale=2.
Someone reads a p-value of as "strong evidence" and as "no evidence at all." What's the flaw?
The cutoff is an arbitrary convention, not a physical wall; two p-values straddling it carry almost identical strength of evidence, so treating them as opposite worlds is a false dichotomy.
To test if the mean is , someone uses ttest_ind(data, [5,5,5,5,5]). Why is that the wrong test?
ttest_ind compares two independent samples; testing one sample against a fixed number is a one-sample test, ttest_1samp(data, popmean=5).
stats.chisquare(obs, exp) is called where several expected counts are or . What's unsound?
The chi-square approximation assumes expected counts are reasonably large (rule of thumb ); tiny expected values make the p-value untrustworthy.
z = (x - mu) / sigma**2 was written to standardize a value. Spot the bug.
You divide by , not — dividing by the variance would give the wrong units and wrong scale; the z-score is .
A one-sided p-value was doubled and then compared to . Why is this a double penalty?
You either double the one-sided p-value (for a two-sided test) and compare to , or keep it one-sided and compare to — doing both applies the correction twice.

Why questions

Why does a two-sided t-test multiply the tail probability by 2 (see figure s03)?
"At least as extreme" means as far from in either direction, so you add both symmetric red tails and , which by symmetry equals .
Why does the standard error of the mean shrink by and not by ?
Variance of a sum of independent values grows like , so the mean's variance is ; taking the square root to get the sd gives . See Central Limit Theorem.
Why can one stats.norm object answer questions about every normal distribution?
The z-transform slides the curve to center (that's loc) and squashes width to (that's scale), mapping any onto the standard . See Normal Distribution.
Why is the PDF defined as the derivative of the CDF?
The CDF accumulates probability (the growing yellow area in figure s02); the density is how fast it accumulates, so probability in a sliver is .
Why use (Student-t) rather than when the population sd is unknown?
Replacing with the sample estimate injects extra randomness; the heavier-tailed widens the critical region to honestly account for that uncertainty.
Why does the sampling distribution of the mean look bell-shaped even when the raw data isn't?
The Central Limit Theorem says sums (and hence averages) of many independent contributions converge to a normal shape regardless of the original distribution. See Central Limit Theorem.
Why does the chi-square statistic divide each squared mismatch by the expected count ?
Dividing by turns a raw squared deviation into a relative one — a gap of 5 matters far more when you expected 10 than when you expected 1000 — so the terms are comparably scaled. See Chi-square Distribution.

Edge cases

What is stats.norm(0,1).cdf(0) and why?
Exactly — the standard normal is symmetric about (figure s01), so half the area lies to the left of the center.
What does the PDF give for a point outside the support, e.g. stats.expon.pdf(-1)?
Zero — the exponential is only defined for , so density is zero everywhere the variable can't occur.
What p-value do you get from a one-sample t-test where the sample mean exactly equals ?
, so the p-value is — the data is perfectly consistent with , giving zero evidence against it.
What breaks in a one-sample t-test with ?
Degrees of freedom , so there is no sample sd to estimate spread (you'd divide by zero) and the distribution is undefined — a single point carries zero information about variability, so the test simply cannot run.
As sample size with unknown, what happens to the distribution?
Its tails thin out and it converges to the standard normal , because estimates almost perfectly and the extra uncertainty vanishes.
What does stats.chisquare return when observed counts equal expected exactly?
Statistic and p-value — no mismatch at all, so there's no evidence against the "expected" model.
What is .ppf(0) and .ppf(1) for a normal?
and — the value below which of mass lies is unbounded below, and is unbounded above, since the normal has infinite support.
Why does 1 - cdf fail in the far tail but .sf survive (figure s04)?
Far out, cdf is like ; subtracting it from leaves only the last few digits, so catastrophic cancellation throws away precision, while .sf computes the tiny tail area directly and keeps every digit.

Recall One-line self-test

Cover every answer above. If you can justify at least 20 of them in a sentence — not guess yes/no — you own the concepts. The traps that trip people most: p-value direction, scale vs , .cdf vs .sf, and "failed to reject proved."