Getting Started with svy-sae

Install svy-sae and learn how its core objects fit together

Getting Started
Installation
Python
Install svy-sae for small area estimation in Python and learn its object model: a model class over a data frame, a fit method per estimator, and a results object with tables, diagnostics, and plots.
Author

Mamadou S. Diallo, Ph.D.

Modified

November 8, 2026

Keywords

install svy-sae, small area estimation Python setup, svy-sae getting started, Fay-Herriot EBLUP EBP Python

This page gets svy-sae installed and gives you a mental model of the library: two model classes, a fit method per estimator, and one results object for all of them. Once the model clicks, the tutorials are deeper dives into each piece.

Installation

Install svy-sae from PyPI using pip:

pip install svy-sae

or, with uv:

uv add svy-sae

svy-sae installs svy with it. Optional extras add features:

Table 1: Optional extras
Install Adds
"svy-sae[spatial]" Neighbours from polygons for spatial models (ContiguityProx), through polars-st
"svy[remote]" The online dataset catalog that the tutorials load their data from

The examples in these docs load their data with svy.datasets, so install both:

pip install svy-sae "svy[remote]"

System requirements:

  • Python 3.12, 3.13, or 3.14
  • Linux, macOS (Apple silicon), and Windows

For virtual environments and uv projects, see the full Installation guide.

The svy-sae Object Model

Every workflow follows the same three moves:

  1. Wrap the data in a model class: AreaLevel for one row per area, UnitLevel for one row per sampled unit.
  2. Fit an estimator with a method of the class, naming the columns it uses.
  3. Read the results from the SAEResults it returns.
import svy
import svy_sae as sae

milk = svy.datasets.load("milk").data

# 1. Wrap the data: one row per area
model = sae.AreaLevel(milk)

# 2. Fit an estimator
fit = model.fh(
    y="yi",
    x=svy.Cat("MajorArea", ref=1),
    variance="variance",
    area="SmallArea",
)

# 3. Read the results
print(fit.stats)
SAEStats(method=REML, n_areas=43, n_obs=43, logLik=12.6775)

The data stay as they are: each fit names its outcome, covariates, and area column, so one model object serves several fits. Covariates are column names, or svy.Cat(...) for a categorical one.

The estimators

Table 2: Model classes and their estimators
Class Method Fits Learn more
AreaLevel fh() Fay–Herriot, with transformations and benchmarking; spatial or temporal effects through random= Fay–Herriot
AreaLevel stepwise() Fay–Herriot models over subsets of covariates, by AIC, BIC, or KIC; returns a Selection Choosing covariates
UnitLevel eblup() Battese–Harter–Fuller, for area means BHF (EBLUP)
UnitLevel ebp() Molina–Rao EBP, for poverty and other nonlinear indicators Molina–Rao (EBP)

sae.smooth_variance() prepares the sampling variances for fh(): see Smoothing variances. Options that take more than a value are small objects passed to the fit: sae.Benchmark(...), sae.LogTransform() and the other transformations, sae.SAR(...) and sae.AR1() for the area effects, and sae.Indicator for the EBP indicators.

Everything hangs off the results

fh(), eblup(), and ebp() all return an SAEResults:

Table 3: Accessing an SAEResults
Access What it gives Learn more
print(fit) Summary: fit statistics, coefficients, variance components, findings
fit.to_polars(...) Each part as a polars DataFrame: "predictions", "fixed", "components", "diagnostics", "tests", "findings", … Quick tour
fit.stats, fit.component(...) Fit statistics (log-likelihood, AIC, BIC, KIC) and one variance component Fay–Herriot
fit.diagnostics Tests, findings under your own thresholds, calibration Checking the model
fit.findings(...) The findings as a table, under your own thresholds Checking the model
fit.refit(...) The same fit with some arguments changed, such as mse="bootstrap" Fay–Herriot
fit.plots Q-Q, residuals, Cook’s distance, shrinkage, and other plots Checking the model

sae.compare(fit_a, fit_b, ...) puts fits side by side, one row each, and AreaLevel.influence() refits a Fay–Herriot model without each influential area: see Checking the model.

For example, one variance component and one test:

print(fit.component("area"))
print(fit.diagnostics.test("shapiro_area_effects"))
VarianceComponent(name='area', kind=variance, est=0.0185503, se=0.00761791)
DiagTest(name='shapiro_area_effects', applies_to='area_effects', statistic=0.8780041497214808, df=None, p_value=0.00028731324435463096, indicator=None, time=None)
NoteWhere the inputs come from

svy-sae fits models; svy handles the survey. Area-level models take direct estimates and their design-based variances, which svy computes from the survey and its design: see Preparing inputs. The example datasets come from svy.datasets.

The first fit on a machine

The model kernels compile on their first use and are cached to disk, so the first fit of a given data shape on a machine takes a few extra seconds, and later fits skip it. svy_sae.warmup() pays that cost ahead of time: see Installation.

Ready to Explore?

Take the five-minute quick tour, then the step-by-step tutorials.

Quick Tour →