Unit averaging in Python: efficient ensemble estimation of unit-specific parameters
Project description
unit_averaging
Optimal Estimation for Heterogeneous Data
|
A Python package for estimating unit-specific parameters in heterogeneous data settings (panel data and meta-analysis). Implements unit averaging: an ensemble method that efficiently combines information across multiple units (e.g., countries, firms, or studies) while accounting for their individual differences. |
|
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. T., & Morozov, V. (2024). Unit Averaging for Heterogeneous Panels:
@misc{Brownlees2024UnitAveragingHeterogeneous,
title = {Unit Averaging for Heterogeneous Panels},
author = {Brownlees, Christian and Morozov, Vladislav},
year = {2024},
month = may,
number = {arXiv:2210.14205},
eprint = {2210.14205},
primaryclass = {econ},
publisher = {arXiv},
doi = {10.48550/arXiv.2210.14205},
archiveprefix = {arXiv},
}
Support
For questions, issues, or contributions:
- Report bugs on our GitHub issues
- Contribute via pull requests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unit_averaging-1.0.0.tar.gz.
File metadata
- Download URL: unit_averaging-1.0.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0ca7c35c8a56284e82bc2bb379b05b814c52f9e22e751288d50bf1d155bf514
|
|
| MD5 |
415db2ebb5b2d30b8913855241153917
|
|
| BLAKE2b-256 |
7bb760da05e8398780f63605efc5c3dd63482c32e3b8b6a08d6df7f72adc5aa2
|
Provenance
The following attestation bundles were made for unit_averaging-1.0.0.tar.gz:
Publisher:
publish-to-pypi.yml on vladislav-morozov/unit-averaging
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unit_averaging-1.0.0.tar.gz -
Subject digest:
f0ca7c35c8a56284e82bc2bb379b05b814c52f9e22e751288d50bf1d155bf514 - Sigstore transparency entry: 524467995
- Sigstore integration time:
-
Permalink:
vladislav-morozov/unit-averaging@4d0ee7c6c02c5ff13259cc30154909e397e28988 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vladislav-morozov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@4d0ee7c6c02c5ff13259cc30154909e397e28988 -
Trigger Event:
push
-
Statement type:
File details
Details for the file unit_averaging-1.0.0-py3-none-any.whl.
File metadata
- Download URL: unit_averaging-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a913ef6863d8c14718531840a75f572dbdc479a5d731d133ba2d4ee6bb857705
|
|
| MD5 |
6b849e820fe40267e283560a66ee5c7a
|
|
| BLAKE2b-256 |
c463706fa78a4fe2664e96b5abc75b6670ce2d6f421b5d9ace3801af8e22803f
|
Provenance
The following attestation bundles were made for unit_averaging-1.0.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on vladislav-morozov/unit-averaging
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unit_averaging-1.0.0-py3-none-any.whl -
Subject digest:
a913ef6863d8c14718531840a75f572dbdc479a5d731d133ba2d4ee6bb857705 - Sigstore transparency entry: 524468023
- Sigstore integration time:
-
Permalink:
vladislav-morozov/unit-averaging@4d0ee7c6c02c5ff13259cc30154909e397e28988 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vladislav-morozov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@4d0ee7c6c02c5ff13259cc30154909e397e28988 -
Trigger Event:
push
-
Statement type: