Zipf’s Law, City Sizes, and Why the Largest City Cheats: A Global Data Experiment
Tags: Zipf's law
Zipf’s Law claims that city populations decrease according to a power law: $$ P(r) = C r^{-\alpha} $$ where $P(r)$ is the population of the $r$-th largest city, and $C, \alpha$ are fitted constants. Classic theory suggests $\alpha \approx 1$, but this varies from region to region.
However, when one plays around finding fits for countries, one often finds that the capital city is often an outlier. This has been extensively noted (see for example Zipf’s Law for Cities: An Explanation from Xavier Gabaix, 1999, from The Quarterly Journal of Economics).
For example, this is the Zipf’s law plot for Colombia, together with the power function of best fit.
But what happens if you ask Zipf’s Law to predict a specific city size? And what if you’re honest about how much the largest city messes up the fit?
This Experiment
Data: SimpleMaps World Cities (city proper, not metro).
For each of the world’s 50 largest countries by population:
- Take the 15 largest cities by population (using most recent data).
- Fit the power law above in two ways:
- To all 15 cities (ranks 1–15)
- To only the “tail” (ranks 2–15, ignoring the largest city)
- Use both fits to predict the population at rank 6 ($r=6$).
- Compute percentage error: $$ \text{Error}(r=6) = \left| \frac{P_\text{fit}(6) - P_\text{actual}(6)}{P_\text{actual}(6)} \right| \times 100% $$
- Sum errors across all countries.
Results: The Outlier Problem in Numbers
Sum of percentage errors across 50 countries:
- All 15 city fit: 1930%
- 2–15 fit (excluding the largest): 611%
So: the classic “fit all cities” approach gives, on average, three times more error at predicting the 6th city’s size.
Example: Malaysia
- All-cities fit predicts the 6th city 76% too small.
- 2–15 fit predicts it almost perfectly: 0.2% error.
Example: United States
- All-cities fit: 2% error.
- 2–15 fit: 1.5% error.
Example: Argentina
- All-cities fit: 75% error.
- 2–15 fit: 1.2% error.
Most countries look like Malaysia or Argentina, not the U.S.
Method (for Replication)
Step 1: Data Preparation
- Download SimpleMaps World Cities CSV
- For each country, extract the 15 largest cities by population.
Step 2: Power Law Fitting
Use non-linear least squares to fit
$$
P(r) = C r^{-\alpha}
$$
using scipy.optimize.curve_fit. Do this both for all cities and for cities 2–15.
Step 3: Prediction and Error Calculation
Predict $P(6)$ from both fits. Compute percent error.
Code Example
import numpy as np
from scipy.optimize import curve_fit
import pandas as pd
def power_law(r, C, alpha):
return C * r ** (-alpha)
# pops = np.array([...]) # 15 largest city populations for one country
ranks = np.arange(1, 16)
# Fit all
popt_all, _ = curve_fit(power_law, ranks, pops, p0=[pops[0], 1.0])
# Fit 2–15
popt_tail, _ = curve_fit(power_law, ranks[1:], pops[1:], p0=[pops[1], 1.0])
pred6_all = power_law(6, *popt_all)
pred6_tail = power_law(6, *popt_tail)
err_all = abs(pred6_all - pops[5]) / pops[5] * 100
err_tail = abs(pred6_tail - pops[5]) / pops[5] * 100
Loop Over All Countries (Pseudocode)
for country in top50_countries:
pops = get_top15_city_pops(country)
do the fits as above...
collect the errors...
sum all errors
Why Isn’t This in the Literature?
Most published studies on Zipf’s law for cities focus on:
-
Estimating the exponent $\alpha$ globally or per country
-
Testing goodness-of-fit on the entire rank-size distribution
-
Arguing about how “Zipf-like” the urban system is as a whole
Very few (maybe none!) do what’s done here:
-
Explicitly measure “how good is the power law at predicting a specific city (like rank 6)?”
-
Systematically compare “fit all” vs. “fit tail” for many countries
-
Sum up predictive errors in this direct way
See e.g.:
-
Gabaix (1999), “Zipf’s Law for Cities: An Explanation” (PDF)
-
Soo (2005), “Zipf’s Law for Cities: A Cross-Country Investigation” (PDF)
-
Ioannides & Overman (2003), “Zipf’s Law for Cities: An Empirical Examination” (PDF)
These all discuss $\alpha$, not how well the law predicts a particular city size, or the impact of outliers on prediction error at a specific rank.
What Does This Mean?
-
If you want a power law to predict typical large cities, ignore the top outlier.
-
For most countries, the largest city is simply “too big” to fit the rest.
-
The classic use of Zipf’s Law (fit everything) systematically underpredicts typical city sizes in outlier-heavy countries.
This suggests textbooks and articles that uncritically plot all cities together are hiding the real variance—especially if you care about prediction.
Conclusion
Zipf’s law works, but only if you fit it to the pack and not the king. If you want to model or predict typical city sizes, don’t let the largest city anchor your curve. The result is not just more elegant—it’s more accurate, too.
Code and data available on request. If you know of papers that directly measure predictive error at a fixed rank (like 6) for Zipf’s Law, or directly compare all-vs-tail fits in this way, let me know!