unit_averaging
Optimal Estimation for Heterogeneous Data
|
A Python package for estimating unit-specific parameters in heterogeneous data settings (panel data and meta-analysis). |
|
Key Features
- Optimal weighting: automatically computes weights that balance bias and variance
- Flexible workflow: works with panel data, meta-analysis, and other heterogeneous datasets
- Versatility: can be used on top of various standard estimation packages
- Customizable: implement your own weighting schemes by subclassing base classes
- Theoretically grounded: based on statistical theory with proven performance
Installation
Install the package with pip:
pip install unit_averaging
Documentation
- Tutorials: step-by-step guides to get started
- API Reference: detailed documentation for all classes/functions
- Theory: mathematical foundations of unit averaging
- Original Paper: complete theoretical treatment
Quick Start
The core workflow of the package in a small synthetic example:
import numpy as np
from unit_averaging import OptimalUnitAverager, InlineFocusFunction
# Example: Forecasting with a linear focus function
x_value = 1.0 # Your covariate (e.g., lagged value)
estimates = { # Dict of unit-specific coefficient estimates
"unit1": np.array([0.5, 0.3]),
"unit2": np.array([0.7, 0.1])
}
covariances = { # Dict of unit-specific covariance matrices
"unit1": np.array([[0.1, 0.0], [0.0, 0.1]]),
"unit2": np.array([[0.1, 0.0], [0.0, 0.1]])
}
# Define focus function: e.g., μ(θ) = θ₀ + θ₁ * x
focus = InlineFocusFunction(
focus_function=lambda coef: coef[0] + coef[1] * x_value,
gradient=lambda coef: np.array([1, x_value])
)
# Create and fit averager
averager = OptimalUnitAverager(
focus_function=focus,
ind_estimates=estimates,
ind_covar_ests=covariances
)
averager.fit(target_id="unit1")
Citation
If you use unit_averaging in your research, please cite:
Brownlees C. and Morozov V. (2025). Unit Averaging for Heterogeneous Panels. Journal of Business & Economic Statistics. doi: 10.1080/07350015.2025.2584579.
@article{Brownlees2024UnitAveragingHeterogeneous,
author = {Brownlees, Christian and Morozov, Vladislav},
title = {{Unit Averaging for Heterogeneous Panels}},
journal = {Journal of Business \& Economic Statistics},
year = {2025},
doi = {10.1080/07350015.2025.2584579},
}
Support
For questions, issues, or contributions:
- Report bugs on our GitHub issues
- Contribute via pull requests
Release files for unit-averaging 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| unit_averaging-1.1.0.tar.gz | 17.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unit_averaging-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.6 kB
Release files / unit_averaging-1.1.0.tar.gz
| Download URL | unit_averaging-1.1.0.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf31fdff557474bdc315927aca6288e6d8ae461c11208d5eb581f29881082070
|
|
BLAKE2b-256 checksum How to use checksums |
a581490ac17b6970708ed7a8c1eb4249889092a3a3c76114a1880277e642e4e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / unit_averaging-1.1.0-py3-none-any.whl
| Download URL | unit_averaging-1.1.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76f431dd5a85bb91da200b5e149f6de1ee9fb83d02e28d63814758b182b88727
|
|
BLAKE2b-256 checksum How to use checksums |
7df3e6ac84a267855a6fb0fdce68a684fc50a0d039193875c730cb2d04254522
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency log