Discrete distribution · also called Zipf's law, zipfian
Zipf distribution
The rank of an item drawn from a population where the -th most common item has frequency proportional to : words in a text (Zipf's law, with near 1, where the second most common word is half as frequent as the first), city sizes, website visits, file requests to a cache. This page uses the finite version over ranks; with it is the discrete uniform.
Zipf probability calculator
P(X ≤ 2) = 0.512126
At the parameters set by the sliders. The shaded region on the plot is the probability; the dots on the CDF mark F at its ends. For a discrete distribution, < and ≤ differ.
PMF
CDF
mean 3.414 · variance 7.121 · sd 2.669 · mode 1 · entropy 1.994 nats
Formulas
| Parameters |
|
|---|---|
| Support | |
| PMF | |
| CDF | |
| Mean | |
| Variance | |
| Mode | |
| Entropy |
is a generalized harmonic number. With the limit exists and is the zeta distribution (NumPy's zipf and SciPy's zipf); SciPy's zipfian is the finite version shown here.
Worked example
Word frequencies in a language follow Zipf's law with over a vocabulary of words. What share of the words in a text are the 10 most common ones?
Ten words make up about 30% of the text, which is roughly what counts of English give for the, of, and, to, a, in, … answer checked by code
How it relates to others
- Special case→ Discrete uniform: Zipf with is the discrete uniform on . checked by code
All the relationships, as a diagram →
In Python
from scipy import stats
import numpy as np
X = stats.zipfian(a=1, n=10)
X.pmf(1) # P(X = 1) = 0.3414
X.cdf(1) # P(X ≤ 1) = 0.3414
X.mean(), X.var() # 3.414, 7.121
X.ppf(0.95) # 95th percentile
X.rvs(size=10, random_state=0)
rng = np.random.default_rng(0)
rng.choice(np.arange(1, 11), p=1 / np.arange(1, 11) / np.sum(1 / np.arange(1, 11)), size=10)SciPy calls the exponent a and the number of ranks n. NumPy's zipf is the infinite (zeta) version, so sample the finite one with choice.
Choosing between this and its neighbours? Which distribution for count data? · Which distribution for extremes and heavy tails?