Skip to main content

unit_averaging

Optimal Estimation for Heterogeneous Data

PyPI License: MIT Python 3.12+ Docs codecov

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.

Logo

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

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:

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)

Source distribution for unit-averaging 1.1.0
File Size Uploaded
unit_averaging-1.1.0.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unit-averaging 1.1.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page