UnitLevel
UnitLevel(data)Unit-level small area estimation (Battese-Harter-Fuller and Molina-Rao).
The population frame is passed to each fit as pop_data, since it belongs to one estimation rather than to the model.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pl.DataFrame | pl.LazyFrame | Survey microdata: one row per sampled unit, with the outcome, the covariates and an area identifier. For a svy.Sample, pass its .data. |
required |
Methods
| Name | Description |
|---|---|
| eblup | Fit the Battese-Harter-Fuller nested-error model and predict area means. |
| ebp | Molina-Rao empirical best prediction of area indicators. |
eblup
eblup(
y,
x,
area,
pop_data,
pop_size=None,
method='reml',
intercept=True,
mse='analytical',
n_reps=1000,
drop_nulls=False,
rng=None,
tol=1e-05,
max_iter=100,
)Fit the Battese-Harter-Fuller nested-error model and predict area means.
Sampled areas get the EBLUP; areas only in pop_data get the regression prediction at their covariate means.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| y | str | Column of the outcome. | required |
| x | str | Feature | Sequence[str | Feature] | Covariates: column names or svy terms such as Cat("region"). |
required |
| area | str | Feature | RE | Column of area identifiers, in data and pop_data. |
required |
| pop_data | pl.DataFrame | pl.LazyFrame | The population: one row per unit, or one row per area with its covariate means when pop_size is given. |
required |
| pop_size | str | None | Column of area population sizes, for pop_data given as area means. |
None |
| method | Literal['reml', 'ml'] | Estimation of the variance components: REML or ML. | 'reml' |
| intercept | bool | Include an intercept. | True |
| mse | Literal['analytical', 'bootstrap'] | “analytical” (Prasad-Rao) or “bootstrap” (parametric). | '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 observation is below this. | 1e-05 |
| max_iter | int | Iteration limit of the optimizer. | 100 |
ebp
ebp(
y,
*,
x,
area,
pop_data,
predictor='ceb',
unit_id=None,
transformation='boxcox',
boxcox_param=None,
boxcox_bounds=(-2.0, 2.0),
transform_shift=0.0,
indicators=(Indicator.POVERTY_HEADCOUNT, Indicator.POVERTY_GAP),
threshold,
n_mc=200,
n_reps=100,
weights=None,
drop_nulls=False,
rng=None,
max_iter=100,
tol=1e-05,
)Molina-Rao empirical best prediction of area indicators.
Fits the nested-error model on a transformed scale, simulates the outcome of every census unit from it, and averages each indicator over n_mc simulated populations. The MSE is a parametric bootstrap.
The census EB (“ceb”) simulates every unit of pop_data and uses the sample only to fit the model, so the survey need not belong to the census. The EB (“eb”) keeps the observed outcomes of sampled units and simulates the rest.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| y | str | Column of the outcome, on its original scale. | required |
| x | str | Feature | Sequence[str | Feature] | Covariates: column names or svy terms such as Cat("region"). |
required |
| area | str | Feature | RE | Column of area identifiers, in data and pop_data. |
required |
| pop_data | pl.DataFrame | pl.LazyFrame | The census: one row per population unit, with the covariates. Its areas are the ones predicted. | required |
| predictor | Literal['ceb', 'eb'] | “ceb” or “eb”. Under “eb” without unit_id, pop_data must hold only out-of-sample units: a full census would count sampled units twice. |
'ceb' |
| unit_id | str | None | Under “eb”, a column identifying units in both data and pop_data; the census rows of sampled units are dropped. |
None |
| transformation | Literal['boxcox', 'log', 'none'] | Applied to y before fitting: “boxcox”, “log” or “none”. |
'boxcox' |
| boxcox_param | float | None | Box-Cox lambda. None estimates it within boxcox_bounds. |
None |
| boxcox_bounds | tuple[float, float] | Interval searched for lambda. | (-2.0, 2.0) |
| transform_shift | float | Added to y before the log or Box-Cox transformation, so every value is positive. |
0.0 |
| indicators | str | Indicator | Callable | Sequence[str | Indicator | Callable] | Names or Indicator members, or functions. A function receives the simulated outcomes of all areas, padded to the largest one, a mask that is 1 for real units, the number of units per area and threshold, and returns one value per area using jax.numpy; its name is its label. Under “boxcox”, unbounded indicators such as the mean can be unstable: prefer “log” or “none” for them, or raise n_mc. |
(Indicator.POVERTY_HEADCOUNT, Indicator.POVERTY_GAP) |
| threshold | float | Callable[[np.ndarray], float] | The poverty line, or a function of the sampled outcomes that returns it. Required even when no indicator uses it. | required |
| n_mc | int | Simulated populations the indicators are averaged over. | 200 |
| n_reps | int | Bootstrap replicates for the MSE; each reruns the simulation. 0 skips the bootstrap. | 100 |
| weights | str | None | Column of survey weights for the pseudo-EBP of Guadarrama, Molina and Rao (2018), which guards against informative sampling; the variance components stay unweighted. Needs “log” or “none”. | None |
| 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 simulation and the bootstrap. | None |
| max_iter | int | Iteration limit of the optimizer. | 100 |
| tol | float | The optimizer stops when the gradient per observation is below this. | 1e-05 |