A probability distribution describes the values a random variable can take and how likely each is. Statistics uses a small family of named distributions over and over: the binomial for counts of successes, the Poisson for counts of events, the normal for measurements that cluster symmetrically, Student's $t$ for standardized means. Each is a formula with a few parameters, and in Python each is an object in scipy.stats with the same set of methods. Using them well is mostly a matter of knowing what those methods compute, how scipy names the parameters, and how to check whether a distribution describes the data at all.
The distributions themselves, with their derivations, means, variances and the conditions under which they arise, are covered in the Applied Statistics pages under Theoretical Probability Distributions: The Binomial Distribution, The Poisson Distribution and The Normal Distribution, with Student's $t$ in Confidence Intervals for a Mean. Here they are summarized in a sentence each and put to work on data from the 2017 to 2018 National Health and Nutrition Examination Survey (NHANES): hypertension among the 5,182 adults of Data Collection and Sampling, men's heights and the number of prescription medicines taken in the past month.
Random variables and their distributions
A random variable assigns a number to each outcome of a random process: the number of adults with hypertension among ten chosen at random, or the height of one man. A discrete random variable takes separate values, usually counts, and its distribution is given by a probability mass function (pmf), $P(X = k)$ for each value $k$. A continuous random variable takes any value in an interval, every single value has probability zero, and its distribution is given by a probability density function (pdf) $f(x)$ whose area over an interval is the probability of landing in it. Both have a cumulative distribution function (cdf), $F(x) = P(X \le x)$, which is the most useful of the three in practice because every probability of an interval can be written with it.
Distribution objects in scipy
Each distribution in scipy.stats can be called with its parameters to give a frozen distribution, an object with the parameters fixed:
from scipy import stats
X = stats.binom(10, 0.5475) # number with hypertension among 10 adults
X.pmf(5), X.cdf(3), X.sf(6), X.ppf(0.5), X.mean(), X.var()
Here $p = 0.5475$ is the share of the 5,182 adults with hypertension, and $X$ counts how many of 10 adults chosen independently with that probability have it, a binomial distribution because each of a fixed number of independent trials has the same probability of success. The methods are the same for every distribution:
| Method | Discrete | Continuous | For $X \sim \text{Binomial}(10, 0.5475)$ |
|---|---|---|---|
pmf(k) / pdf(x) |
$P(X = k)$ | density $f(x)$ (not a probability) | pmf(5) = 0.2352 |
cdf(x) |
$P(X \le x)$ | $P(X \le x)$ | cdf(3) = 0.1050 |
sf(x) |
$P(X > x)$ | $P(X > x)$ | sf(6) = $P(X \ge 7)$ = 0.2607 |
ppf(q) |
smallest $k$ with $F(k) \ge q$ | $F^{-1}(q)$ | ppf(0.5) = 5 |
isf(q) |
inverse of sf |
inverse of sf |
|
rvs(size, random_state) |
random draws | random draws | |
interval(c) |
central range with probability at least $c$ | central range with probability $c$ | interval(0.95) = (2, 8) |
stats("mvsk") |
mean, variance, skewness, excess kurtosis | 5.4747, 2.4775, $-0.0603$, $-0.1964$ |
The mean $np = 5.4747$ and variance $np(1-p) = 2.4775$ are the binomial formulas derived in The Binomial Distribution. The same methods exist without freezing, as stats.binom.pmf(5, 10, 0.5475), with the parameters passed to every call; the frozen form is clearer when one distribution is used many times. A Bernoulli variable, a single trial, is stats.bernoulli(p), the same as stats.binom(1, p): both give $P(X = 1) = 0.5475$.
Discrete distributions: three traps
"At least" needs sf(k - 1). sf(k) is $P(X > k)$, strictly greater. For a count, $P(X \ge 7) = P(X > 6)$ is sf(6) = 0.2607; sf(7) = 0.0968 is $P(X \ge 8)$. The same off-by-one affects 1 - cdf(k), which is also $P(X > k)$. For continuous variables the distinction disappears, because single values have probability zero.
ppf returns a value with cumulative probability at least $q$. For the binomial above, cdf(4) = 0.2670 and cdf(5) = 0.5022, so ppf(q) is 5 for every $q$ between 0.2670 and 0.5022. The inverse of a step function is not unique, and scipy chooses the smallest value whose cdf reaches $q$.
interval covers at least, not exactly, the requested probability. interval(0.95) returns (2, 8), and $P(2 \le X \le 8) = 0.9729$: the discrete distribution cannot hit 0.95 exactly, so the interval is wider. Tests and intervals for proportions inherit this, which is why exact binomial tests are conservative (Inference for Proportions and Means).
Tails: sf rather than 1 - cdf
In floating-point arithmetic, 1 - cdf(x) loses all precision once cdf(x) rounds to 1. For the standard normal:
| $z$ | norm.sf(z) |
1 - norm.cdf(z) |
|---|---|---|
| 3 | $1.3499 \times 10^{-3}$ | $1.3499 \times 10^{-3}$ |
| 6 | $9.8659 \times 10^{-10}$ | $9.8659 \times 10^{-10}$ |
| 8.5 | $9.4795 \times 10^{-18}$ | 0 |
| 10 | $7.6199 \times 10^{-24}$ | 0 |
By $z = 8.5$ the subtraction returns exactly zero, while sf computes the tail directly. Very small tail probabilities matter in practice for p-values from large samples and in multiple-testing corrections that multiply them. For the most extreme cases, logsf returns the logarithm: norm.logsf(40) is $-804.608$, while norm.sf(40) underflows to 0. Quantiles far in the tail likewise come from isf: norm.isf(1e-12) = 7.0345.
Location and scale
Most continuous distributions in scipy take two standard arguments, loc and scale, which shift and stretch a standard form: if $Z$ has the standard form, $X = \text{loc} + \text{scale} \times Z$. The convention is uniform across scipy, which is its advantage, and it does not always match the parameters a textbook uses, which is its trap.
- Normal:
norm(loc=mu, scale=sigma);scaleis the standard deviation, not the variance.norm(120, 16).var()is 256. - Exponential:
expon(scale=beta)has mean $\beta$, so a rate $\lambda$ is passed asscale=1/lam. $P(T \le 1)$ is 0.3935 forexpon(scale=2), a mean of 2, and 0.8647 for a rate of 2 (scale=0.5). The two readings of "exponential with parameter 2" differ by a factor of more than two. - Uniform:
uniform(loc, scale)is uniform on $[\text{loc}, \text{loc} + \text{scale}]$.stats.uniform(2, 5)runs from 2 to 7, not from 2 to 5. - Discrete distributions take
loconly, as a shift:poisson(2.3, loc=1)has mean 3.3.
Reading the parameterization in the documentation of each distribution before using it is the only reliable rule. Newer versions of scipy add a second interface, classes such as stats.Normal(mu=..., sigma=...) with explicitly named parameters and methods named ccdf and icdf for the survival and inverse functions; scipy 1.15.2 has Normal and Uniform, and scipy 1.18.1 also Binomial and Logistic.
Student's t against the normal
When a mean is standardized by an estimated standard deviation, the result follows Student's $t$ distribution with $n - 1$ degrees of freedom rather than the normal, because the estimate adds variability (Confidence Intervals for a Mean derives it). Its tails are heavier, and the difference shrinks as the degrees of freedom grow:
| $P(T > 2)$ | 0.975 quantile | Standard deviation | |
|---|---|---|---|
| $t$, 3 df | 0.0697 | 3.1824 | 1.7321 |
| $t$, 10 df | 0.0367 | 2.2281 | 1.1180 |
| $t$, 30 df | 0.0273 | 2.0423 | 1.0351 |
| $t$, 100 df | 0.0241 | 1.9840 | 1.0102 |
| Normal | 0.0228 | 1.9600 | 1 |
The 0.975 quantile is the multiplier of a 95% interval. With 10 degrees of freedom the $t$ multiplier, 2.2281, is about 14% larger than 1.96, and using the normal quantile instead, as stats.norm.interval does, makes the interval too narrow; Inferential Statistics in Python shows the difference on a sample.
Does a distribution fit the data?
A named distribution is a model, and data are not obliged to follow it. Two checks on NHANES show one model that fits and one that does not.
Men's heights and the normal distribution
The 2,630 men with a measured height have mean 173.481 cm. stats.norm.fit(h) estimates the two parameters by maximum likelihood, which for the normal gives the sample mean and the standard deviation with divisor $n$, 7.675 cm (7.676 with divisor $n - 1$). The fitted model then predicts probabilities that can be compared with the shares in the data:
| Quantity | Normal model | Data |
|---|---|---|
| $P(H > 190)$ | 0.0157 | 0.0152 |
| $P(H < 160)$ | 0.0395 | 0.0414 |
| $P(165 < H < 180)$ | 0.6676 | 0.6654 |
| 90th percentile | 183.32 cm | 183.40 cm |
The agreement is within a few thousandths. The sample skewness is 0.0065 and the excess kurtosis $-0.0634$, both close to the normal's zero, and the correlation of the normal probability plot from stats.probplot is 0.99983. The Normal Distribution discusses these checks and formal tests of normality on the same population, and Visualizing Data with One Feature why heights of men and women together are not bimodal even though each sex's are normal.
Prescription counts and the Poisson distribution
The number of prescription medicines an adult took in the past month is a count, and the Poisson distribution is the standard first model for counts of events. It has one parameter, the mean $\lambda$, and its variance equals its mean (The Poisson Distribution). For the 5,524 adults with a recorded count, the mean is 2.2989 but the variance is 9.4578, four times larger, and 41.4% take no medicine at all. A Poisson distribution with the same mean, stats.poisson(2.2989), gives $P(X = 0) = 0.1004$, a quarter of the observed share; and it gives 10 or more medicines a probability of 0.000143, where the data have 3.6%.
The mismatch is overdispersion (The Poisson Distribution tests for it with Fisher's index of dispersion): the counts vary more than a Poisson model allows, because people differ in their underlying rates. Most take nothing; some take many, for several chronic conditions. A negative binomial distribution, which arises when Poisson rates themselves vary across people, has a second parameter that lets the variance exceed the mean. In scipy's parameterization, nbinom(n, p) has mean $n(1-p)/p$ and variance $n(1-p)/p^2$; matching these to the sample mean and variance gives
$$p = \frac{\bar{x}}{s^2} = \frac{2.2989}{9.4578} = 0.2431, \qquad n = \frac{\bar{x}\,p}{1-p} = 0.7382.$$
| Medicines | Data | Poisson | Negative binomial |
|---|---|---|---|
| 0 | 0.4144 | 0.1004 | 0.3520 |
| 1 | 0.1531 | 0.2307 | 0.1967 |
| 2 | 0.0965 | 0.2652 | 0.1294 |
| 3 | 0.0787 | 0.2032 | 0.0894 |
| 4 | 0.0634 | 0.1168 | 0.0632 |
| 5 | 0.0478 | 0.0537 | 0.0454 |
| 6 | 0.0391 | 0.0206 | 0.0328 |
| 10 or more | 0.0360 | 0.000143 | 0.0368 |
The negative binomial matches the tail and most of the excess at zero; it still underestimates the zeros, 0.352 against 0.414, which suggests that taking no medicine at all is partly a separate state (no chronic condition) rather than the low end of a continuum. Models for such data add a separate probability of a structural zero. The broader point is that the choice of distribution is a claim about the data that should be checked, and that for counts the first check, the variance against the mean, takes one line.
Fitting and simulating
dist.fit(data) estimates parameters by maximum likelihood, and by default it estimates loc and scale too, even for distributions whose standard form starts at zero. For exponential data, which start at zero, the free location is estimated at the smallest observation. In 200 samples of 50 from an exponential distribution with mean 2, for each of 30 seeds, the average fitted loc was 0.0396 (median over seeds; IQR 0.0370 to 0.0410) and the average fitted scale 1.9615, slightly too small; fixing the location with expon.fit(x, floc=0) gave the maximum-likelihood estimate of the mean, the sample mean, averaging 2.0026. The effect is small here, but for distributions with shape parameters, such as the gamma or Weibull, a free location can change the fit substantially. Fixing parameters that the model fixes (floc=0, fscale=...) is the safe habit.
dist.rvs(size=..., random_state=rng) draws random values, reproducibly when rng is a seeded NumPy Generator: stats.binom(10, 0.5475).rvs(size=8, random_state=np.random.default_rng(0)) returns 5, 6, 8, 9, 4, 3, 5, 5 on every run. Simulation from fitted distributions is the basis of parametric bootstrap methods and of checking a model by comparing data simulated from it with the data observed; Probability Fundamentals covers Generators and the Monte Carlo error of such simulations.
Corrections to the course notes
The unit's notes give the definitions and scipy calls accurately; a few points are stated more precisely here. They compute "greater than" probabilities as 1 - cdf(k), which is correct but loses precision in the far tail, where sf(k) should be used, and they leave the strict and non-strict inequalities for discrete variables to the reader, which is where the sf(k - 1) rule comes in. They describe the pdf's value as used "for plotting"; it is also what maximum likelihood fitting and Bayes' theorem for continuous variables work with. Their exam-score and ball-bearing examples come from the course text; the examples here use NHANES data.
In Python
import numpy as np
from scipy import stats
X = stats.binom(10, 0.5475)
X.pmf(5), X.cdf(3), X.sf(6) # P(X = 5), P(X <= 3), P(X >= 7)
stats.norm.sf(8.5), stats.norm.logsf(40) # tails without cancellation
stats.expon(scale=1 / rate) # scale is the mean, not the rate
stats.t(df=9).ppf(0.975) # multiplier for a 95% interval, n = 10
mu, sd = stats.norm.fit(heights) # maximum likelihood: sd uses divisor n
(osm, osr), (slope, intercept, r) = stats.probplot(heights, dist="norm")
m, v = counts.mean(), counts.var(ddof=1)
nb = stats.nbinom(m * (m / v) / (1 - m / v), m / v) # negative binomial by moments
stats.expon.fit(x, floc=0) # fix parameters the model fixes
X.rvs(size=1000, random_state=np.random.default_rng(0))
The numbers in this article are computed by tools/experiments/data-science/probability-distributions.py in the site's repository, from the NHANES tables built by exploredata.py and psdata.py; the results are the same with scipy 1.15.2 and 1.18.1 except for the list of new-style classes. The figure is drawn by tools/figures/probability-distributions.py.
References
- National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018 data files and documentation (DEMO_J, BMX_J, BPX_J, BPQ_J, RXQ_RX_J). Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 45 pages
- SciPy developers (2026). Statistical functions (
scipy.stats): continuous and discrete distributions,rv_continuous.fit,probplot. SciPy reference guide. https://docs.scipy.org/doc/scipy/reference/stats.html record