Poverty Indicators with the EBP in Python with svy-sae
The Molina–Rao empirical best predictor of nonlinear indicators
Tutorials
Unit-level
EBP
Poverty Mapping
Python
Estimate poverty rates, gaps, and other nonlinear indicators for small areas in Python with the Molina-Rao EBP in svy-sae: Box-Cox and log transformations, Monte Carlo simulation over the census, custom indicators, and bootstrap MSE.
Author
Mamadou S. Diallo, Ph.D.
Modified
November 8, 2026
Keywords
Molina-Rao model, empirical best prediction Python, EBP poverty mapping, poverty headcount gap severity, Box-Cox transformation SAE, nonlinear indicators small area estimation
WarningAbout these examples
This tutorial illustrates the svy-sae API; it is not a rigorous small area analysis. The models are kept simple so each step stays readable, and in many places, from the choice of covariates to the variance model, better choices could be made to improve them.
A district mean is linear in the outcome, so the BHF model predicts it from the census means of the covariates. A poverty rate, a poverty gap, or a Gini coefficient is not: it depends on the whole distribution of expenditure in the district, household by household.
The empirical best predictor (EBP) of Molina and Rao (Molina and Rao 2010) handles any such indicator. It fits the nested error model on a transformed scale, then simulates the expenditure of every census household from the model given the sample, computes the indicator for each district on each simulated population, and averages over n_mc simulations. Its MSE comes from a parametric bootstrap, each replicate of which repeats the simulation.
This tutorial demonstrates how to estimate the poverty headcount, gap, and severity (Foster, Greer, and Thorbecke 1984) and other indicators of district expenditure with UnitLevel.ebp(), choose a transformation, write a custom indicator, and weigh precision against computing time.
Mean shortfall below the threshold, as a share of it
Indicator.POVERTY_SEVERITY
"severity", "fgt2"
Mean squared shortfall: weighs the poorest more
Indicator.MEAN
"mean"
Mean of the outcome
Indicator.MEDIAN
"median"
Median of the outcome
Indicator.GINI
"gini"
Gini coefficient of the outcome
Indicator.QSR
"qsr"
Quintile share ratio: top fifth’s share over the bottom fifth’s
The defaults are the headcount and the gap. threshold is required, also for indicators that do not use it.
A custom indicator
An indicator can be a function. It receives the simulated outcomes of all districts at once, padded to the largest district, and returns one value per district. It runs inside the compiled simulation, so it uses jax.numpy. The poverty severity, written out:
y holds the simulated outcomes, mask is 1 for real households and 0 for padding, n_units counts the households of each district, and threshold is the poverty line. The function’s name becomes the indicator’s label:
With "none", the simulation draws expenditures that are normal around the regression, and the data are not; the poverty rates have the largest errors. The log and Box–Cox scales match the data far better.
WarningUnbounded indicators under Box–Cox
The inverse Box–Cox transform raises its argument to the power \(1/\lambda\), so a single extreme simulated draw can back-transform to an enormous value and dominate a district’s mean. svy-sae warns when an estimate exceeds ten times the largest observed outcome. The headcount, gap, and severity look only below the poverty line and cannot be affected, nor can the median; the mean, Gini, and QSR can. For those, prefer "log" or "none" if the warning appears, or raise n_mc.
Precision and computing time
Two settings control the cost:
n_mc (default 200): simulations behind each estimate. It sets the Monte Carlo error of the estimates.
n_reps (default 100): bootstrap replicates for the MSE. Each replicate repeats the whole simulation over the census, so the cost grows with n_reps; n_reps=0 returns point estimates only.
The indicators differ in cost. The poverty measures and the mean add little to a fit; the median, Gini, and QSR need the simulated outcomes sorted in every district, which multiplies the time of a bootstrap several times over. Their point estimates are cheap:
The settings here keep the tutorial quick to run; production estimates use more of both. The first fit on a machine also compiles the simulation, which svy_sae.warmup() does ahead of time (see Installation).
How close did we get?
Compare each indicator of the main fit with the truth: error, average MSE, average squared error, and intervals that contain the true value:
The poverty rate’s error is about half that of the area-level Fay–Herriot model (0.033) on the same districts, and the mean’s is below both the BHF model’s (333) and the area-level model’s (197). On a scale that fits the data, the household records carry information that district aggregates lose.
The MSE is again below the actual squared error, and fewer intervals than intended contain the truth. Fifty replicates leave a noisy MSE, and the model, though much closer to the data than the BHF model, still simplifies it.
Summary
This tutorial estimated poverty indicators with UnitLevel.ebp():
Simulation over the census: every household, n_mc times, on a Box–Cox or log scale
Indicators: the poverty headcount, gap, and severity, the mean, median, Gini, and QSR, and custom functions
Thresholds as a number or a function of the sample
Transformations: the fit scale matters most for poverty rates
Cost: n_reps repeats the simulation; rank-based indicators cost more
Accuracy: about half the error of the area-level model for the poverty rates
Next steps
The EBP treats the sample as if it were drawn at random within districts. When the selection depends on the outcome, survey weights can correct for it.