Skip to main content

statspai-hdfe

Rust kernels for StatsPAI: high-dimensional fixed-effect (HDFE) demeaning, the native IRLS (Poisson, logit, probit) behind sp.fepois / sp.feglm / sp.fast.fepois, and the cluster-robust sandwich meat.

pip install statspai-hdfe        # StatsPAI releases after 1.39.6 install it themselves

StatsPAI releases after 1.39.6 depend on this package on every platform with a wheel (Linux x86_64 / aarch64, macOS, Windows x64). Without it the same functions run on NumPy / Numba and agree with the Rust path to within the residualisation tolerance. Check which one is in use:

import statspai as sp
sp.fast.backend_info()      # {'available': True, 'version': '0.9.0', 'threads': 8, ...}
sp.fast.set_num_threads(4)  # or set STATSPAI_NUM_THREADS before starting Python

STATSPAI_SKIP_RUST=1 makes StatsPAI ignore an installed extension.

What uses it

StatsPAI entry point Kernel
sp.fast.feols, sp.fast.demean, sp.fast.within, sp.fast.event_study demean_2d
sp.fast.feols(weights=), sp.ppmlhdfe (two or more FEs) demean_2d_weighted
sp.fepois, sp.fast.fepois fepois_irls, separation_mask
sp.feglm(family="logit" / "probit") feglm_irls (API 3)
sp.feols (plain formulas, backend="auto") demean_2d
sp.iv(absorb=), sp.didregress, sp.iv.iv_diag, weak-IV diagnostics demean_2d
sp.regress(cluster=) (one-way) cluster_meat
singleton pruning in sp.fast singleton_mask

sp.panel and the calls sp.feols hands to pyfixest (IV, i(), csw(), other variances) do not use it.

Algorithm

The fixed-effect projection is solved in the space of FE coefficients, as fixest does (Bergé 2018; paper.bib key berge2018efficient):

  • Two FEs. One Gauss-Seidel sweep needs only the group sums of the column and the sparse cross-tabulation of the two FEs, so it costs O(nnz) instead of O(n); on panels where a unit meets few levels of the other FE (worker x firm, firm x year) that is a small fraction of the rows. The iteration runs on the coefficients of the smaller FE and is accelerated with Irons-Tuck at every step.
  • Three or more FEs. The two FEs with the most levels form a block solved by the two-FE routine (warm-started) inside an outer Gauss-Seidel over the others, accelerated with Irons-Tuck. The inner tolerance starts loose and follows the outer change down.
  • Stopping rule. Stop when the bound on the change of the residual between two sweeps is at most tol_abs + tol_rel * max|x|, the rule of the NumPy reference in statspai.fast.demean.
  • IRLS. The FE structure is built once per fepois call; each iteration re-weights it and restarts every column from its FE coefficients of the previous iteration.

Columns are processed in parallel, and from crate 0.9 so is every pass over the rows within a column (group sums, residuals, the IRLS working response, cross products, deviance): the rows are split into chunks fixed by the problem size, each chunk is reduced in row order, and the chunk results are added in chunk order (src/par.rs). A fit is therefore bit-identical at any thread count. The cluster meat sums fixed blocks of clusters the same way.

Safety

Every entry point validates lengths, contiguity and code ranges before running and raises ValueError on bad input. The crate is built with panic = "unwind", so an unexpected panic surfaces as a Python exception instead of aborting the interpreter. The kernels run on their own thread pool (never Rayon's global one), which is rebuilt in a forked child.

Build from source

pip install maturin
cd rust/statspai_hdfe
maturin develop --release       # into the active environment
maturin build --release         # a wheel in target/wheels
PYO3_PYTHON=python cargo test --release

Wheels are abi3: one per platform serves every CPython >= 3.10. The rust-hdfe GitHub workflow tests the crate on Linux, macOS and Windows, and builds wheels on demand; releases are uploaded from those wheels with twine.

Kernel API

statspai_hdfe.API_VERSION names the interface level; StatsPAI ignores an extension older than the level it was written against (statspai._rust_backend.MIN_API_VERSION) and warns once.

Level Crate Change
1 0.1 – 0.7 data-space alternating projections; inputs not validated
2 0.8 coefficient-space solver; validated inputs; fepois_irls reports singular / fe_converged; thread-pool control; reproducible cluster_meat
3 0.9 feglm_irls(..., family) for Poisson / logit / probit; row-parallel passes, bit-identical at any thread count; API 2 entry points unchanged

License

MIT.

Metadata

Release files for statspai-hdfe 0.9.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 statspai-hdfe 0.9.0
File Size Uploaded Provenance
statspai_hdfe-0.9.0.tar.gz 45.7 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for statspai-hdfe 0.9.0
File
statspai_hdfe-0.9.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
statspai_hdfe-0.9.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
statspai_hdfe-0.9.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
statspai_hdfe-0.9.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
statspai_hdfe-0.9.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
statspai_hdfe-0.9.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.7 MB

Release files / statspai_hdfe-0.9.0.tar.gz

Download URL statspai_hdfe-0.9.0.tar.gz
Size 45.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5a337e04c73ab30b002367ce207f5f94f06eb7146dbe021ccc7ad80a2922ec6b
BLAKE2b-256 checksum
How to use checksums
53cc952c2860202497119cbb3be9e140153551989666ebdc08a6f8715476de23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / statspai_hdfe-0.9.0-cp310-abi3-win_amd64.whl

Download URL statspai_hdfe-0.9.0-cp310-abi3-win_amd64.whl
Size 341.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c7da6e287dfdccd87a055b14da4338cea37597e102f47cafcdb5c9765427a37f
BLAKE2b-256 checksum
How to use checksums
a4255729e3383e2ce45658bbd34f8569ad1f46fcdef1f6942ff30774967d0217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / statspai_hdfe-0.9.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL statspai_hdfe-0.9.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 655.0 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
422bd2f2889406a4193f09a34605927079f415ee346b7a586a1a9597863e9905
BLAKE2b-256 checksum
How to use checksums
8fd7803b6b900c8f04efad3b8668b853d54b23d3b81036e6bbf86c5814ef9a92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / statspai_hdfe-0.9.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL statspai_hdfe-0.9.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 444.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f44f029790699e9d2560b33a28ea779b60a6f149f5fc4aac61b200a971fe5a4b
BLAKE2b-256 checksum
How to use checksums
cec14bddad53a8f7f4e921071e3a294860a64a5081a8885b39a395fcaac0d6a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / statspai_hdfe-0.9.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL statspai_hdfe-0.9.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 435.4 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
22937f96ff7a631aca4619745d94cce222436ee129e45a31f993ef8f3e19bb97
BLAKE2b-256 checksum
How to use checksums
dd31a5023ae8d537358af3b775eb82ce42c26aef85bc100070969bd5cf173b6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / statspai_hdfe-0.9.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL statspai_hdfe-0.9.0-cp310-abi3-macosx_11_0_arm64.whl
Size 402.9 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b4b6e981084e06604886a216880563609cb02ffb7e1d8a08c995d882ada6cad6
BLAKE2b-256 checksum
How to use checksums
bc15536d04b4dfbc1b9594e4f8e7c98c0081f4cb83e5af6a8be814bcf74e818a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / statspai_hdfe-0.9.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL statspai_hdfe-0.9.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 418.3 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
007e4769cd3740579feb30c68840328381d7cd38de6a5a157e04d5e3a838982b
BLAKE2b-256 checksum
How to use checksums
f0d5240749818ea93356276f52cff94ca61231679b9b942c5b9499221e494909
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Security for statspai-hdfe 0.9.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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