htc
htc · Horvitz-Thompson continuous-population estimator functions for PostgreSQL.
Overview
PostgreSQL · 16
| Relationships | |
|---|---|
| Requires | plpython3u postgis |
Usage
Sources:
htc implements Horvitz-Thompson estimators for continuous-population sampling. It targets specialized survey and forest-inventory calculations, accepting sampled cluster, density, weight, area, inclusion-probability, and auxiliary-variable arrays rather than ordinary row aggregates.
Core Workflow
Install the procedural and numerical prerequisites used by the upstream version before creating htc:
For the original one-phase interface, aggregate one stratum into aligned arrays and pass the stratum constants explicitly:
Use the upstream regression workflow as the canonical guide for preparing those arrays and interpreting the returned total and var values; estimator validity depends on preserving the required ordering, shapes, units, and sampling-design assumptions.
Object Index
htc_compute(...)returns one-phasetotalandvarestimates from C.htc_compute_sweight_ha(...)is the sampling-weight-per-hectare variant.htc_gbeta(...)builds generalized regression coefficients from JSONB matrices.htc_total2p(...)returns a two-phase total, total variance, and variance components for each phase.htc_variance_phase1(...)andhtc_variance_phase2(...)are two-phase variance helpers.htc_version()andhtc_version_ok()check that the loaded shared library matches the SQL release.
Operational Notes
Version 2.1 is relocatable and has no preload requirement. Its newer two-phase routines are plpython3u functions importing NumPy and SciPy, so those Python modules must be available to PostgreSQL’s server-side Python. plpython3u is untrusted and normally requires superuser-level control to install; restrict who can replace or invoke procedural code.
The JSONB routines validate array counts, dimensions, nulls, and forbidden zero probabilities, but that does not validate the statistical design. Treat the upstream regression inputs as schemas, verify htc_version_ok() after binary or SQL upgrades, and independently validate estimator results before operational decisions.