AreaLevel

AreaLevel(data)

Area-level small area estimation (Fay-Herriot).

Direct estimates and their variances come from survey estimation, e.g. svy’s sample.estimation.mean(y=..., by=<area>), joined to the area covariates.

Parameters

Name Type Description Default
data pl.DataFrame | pl.LazyFrame One row per area: the direct estimate, its sampling variance and the covariates. A svy.Sample is refused: aggregate it to areas first. required

Methods

Name Description
fh Fit the Fay-Herriot model and predict every area.
influence Refit the Fay-Herriot model without each area in turn, re-estimating sigma_u^2.
stepwise Choose covariates among the terms of x by ML fits.

fh

fh(
    y,
    *,
    x,
    area,
    variance,
    random=Independent(),
    time=None,
    pop_data=None,
    transformation='none',
    benchmark=None,
    method='reml',
    mse='analytical',
    n_reps=1000,
    drop_nulls=False,
    rng=None,
    tol=1e-05,
    max_iter=100,
)

Fit the Fay-Herriot model and predict every area.

Sampled areas get the EBLUP, which shrinks the direct estimate toward the regression prediction; areas only in pop_data get the regression prediction.

Parameters

Name Type Description Default
y str Column of direct estimates. required
x str | Feature | Sequence[str | Feature] Covariates: column names or svy terms such as Cat("region"); [] fits an intercept only. required
area str | Feature | RE Column of area identifiers. required
variance str Column of the direct estimates’ sampling variances, on the original scale. required
random Independent | SAR | AR1 Structure of the area effects: Independent, SAR for spatial correlation, or AR1 for the Rao-Yu panel model. Independent()
time str | None Period column for panel data, one row per area and period; needs random=AR1(). None
pop_data pl.DataFrame | pl.LazyFrame | None One row per area to predict, with its covariates. Areas absent from data get the regression prediction; covariate columns missing from data are read from here. None
transformation Literal['none', 'log', 'arcsin', 'logit'] | FHTransform Applied to the direct estimates before fitting: a name, or a LogTransform, ArcsinTransform or LogitTransform to choose the back-transformation. Predictions and MSEs come back on the original scale. 'none'
benchmark Benchmark | None Adjusts the predictions so each group’s size-weighted mean equals its target; needs mse="bootstrap". None
method Literal['reml', 'ml'] Estimation of the area-effect variance: REML or ML. 'reml'
mse Literal['analytical', 'bootstrap'] “analytical” is the Prasad-Rao MSE without a transformation and, under the log, Slud-Maiti for the “bc” back-transformation (needs ML) or the “crude” one. Other transformations need “bootstrap”, a parametric bootstrap. AR1 fits have only the analytical MSE. 'analytical'
n_reps int Bootstrap replicates; used with mse="bootstrap". 1000
drop_nulls bool Drop rows with nulls in the model’s columns. Otherwise a null raises. False
rng int | RNGLike | None Seed or generator for the bootstrap. None
tol float The optimizer stops when the gradient per area is below this. 1e-05
max_iter int Iteration limit of the optimizer. 100

influence

influence(
    y,
    *,
    x,
    area,
    variance,
    pop_data=None,
    transformation='none',
    method='reml',
    areas=None,
    drop_nulls=False,
    tol=1e-05,
    max_iter=100,
)

Refit the Fay-Herriot model without each area in turn, re-estimating sigma_u^2.

One row per deleted area: its Cook’s distance (sigma_u^2 held) and from the refit (cooks_d_refit), the change in sigma_u^2 and in each coefficient in standard errors (dfbetas_<term>), and the largest change in another area’s estimate on the original scale, before benchmarking. Point estimates only, without an MSE.

Parameters

Name Type Description Default
y str As for fh. required
x str As for fh. required
area str As for fh. required
variance str As for fh. required
pop_data str As for fh. required
transformation str As for fh. required
method str As for fh. required
drop_nulls str As for fh. required
tol str As for fh. required
max_iter str As for fh. required
areas Sequence | None Areas to delete. None takes those findings flags as influential: Cook’s distance above 4 / number of sampled areas. None

stepwise

stepwise(
    y,
    *,
    x,
    area,
    variance,
    pop_data=None,
    transformation='none',
    random=Independent(),
    direction='both',
    criterion='aic',
    start=None,
    vif_max=None,
    drop_nulls=False,
    tol=1e-05,
    max_iter=100,
    max_steps=1000,
)

Choose covariates among the terms of x by ML fits.

Each step drops or adds the one term that lowers the criterion most, and stops when none does. Fits are on the transformed scale, without an MSE.

Parameters

Name Type Description Default
y str As for fh. required
area str As for fh. required
variance str As for fh. required
pop_data str As for fh. required
transformation str As for fh. required
drop_nulls str As for fh. required
tol str As for fh. required
max_iter str As for fh. required
x str | Feature | Sequence[str | Feature] Candidate terms, as for fh. required
random Independent | SAR Independent or SAR area effects. Independent()
direction Literal['both', 'forward', 'backward'] “forward” only adds terms, “backward” only drops them, “both” does either. 'both'
criterion Literal['aic', 'bic', 'kic'] Information criterion to minimize. 'aic'
start str | Sequence[str] | None Terms of the first model. None starts from all of x, or from none with direction="forward". None
vif_max float | None A term is added only if every VIF of the new model stays at or below this. None
max_steps int Most steps taken before stopping. 1000