This release is a pre-release and may not be stable for production use.
longmi
longmi creates multiple plausible versions of missing repeated outcomes, fits the same analysis to each version, and combines the estimates and uncertainty using Rubin's rules.
It is designed for one incomplete longitudinal outcome and makes the assumptions behind every result explicit — as part of the result object, not only in a paper.
Incomplete longitudinal data
↓
Fit an imputation model
↓
Generate M completed datasets
↓
Fit the same analysis M times
↓
Pool estimates and uncertainty
↓
Report the result and its validity conditions
Installation
pip install longmi # core imputation and pooling
pip install "longmi[analysis]" # plus the statsmodels GEE/GLM adapters
The quickstart below uses the analysis extra. From a checkout for
development: pip install -e ".[dev]".
Quickstart
from longmi import LongitudinalData, pool_rubin
from longmi.analysis import StatsmodelsGEE
from longmi.impute import NegativeBinomialImputer
data = LongitudinalData(
frame, # long format, NaN where the outcome is missing
id_col="subject",
time_col="period",
outcome_col="seizures",
predictor_cols=("treatment", "baseline_seizures", "age"),
outcome_type="count",
times=(1, 2, 3, 4), # declared design grid
)
# treatment-by-wave terms keep the analysis's interaction represented
# in the imputation model (assumption A8)
imputer = NegativeBinomialImputer(time_interactions=("treatment",))
fit = imputer.fit(data) # validate, estimate, diagnose once
completed = fit.impute(m=50, random_state=20260723)
analysis = StatsmodelsGEE(
"seizures ~ treatment * period + baseline_seizures + age",
groups="subject",
family="poisson",
cov_struct="exchangeable",
)
result = pool_rubin(completed.analyze(analysis), validity=completed.declaration)
print(result.summary())
print(result.validity_report())
The same fitted model reruns under a missing-not-at-random scenario:
from longmi import DeltaAdjustment
import numpy as np
shifted = fit.impute(m=50, random_state=20260723,
delta=DeltaAdjustment(np.log(0.8))) # means x 0.8
What is implemented
- Data contract —
LongitudinalDatavalidates the participant-wave grid, preserves observed outcomes bit-for-bit through completion, and enforces count support (src/longmi/data.py). - Imputers —
JointGaussianImputer(continuous outcomes; exact conjugate data augmentation, wave-saturated mean, unstructured covariance) andNegativeBinomialImputer(longitudinal counts; NB random intercept, Gauss–Hermite ML with verified convergence, large-sample posterior-approximation parameter draws, adaptive-grid random-intercept draws, gamma–Poisson outcome draws). Both support delta-adjusted MNAR sensitivity analysis and report numerical diagnostics; a failed fit refuses to impute. - Analyses —
StatsmodelsGEE(marginal GEE, robust sandwich, verified to reproduce direct statsmodels fits exactly),StatsmodelsGLM, andCallableAnalysisfor custom estimators. - Pooling —
pool_rubin, multivariate, bit-compatible withmice::pool.scalar(verified at 1e-12 against R), Barnard–Rubin degrees of freedom, fraction of missing information, andvalidity_report()distinguishing verified properties from declared assumptions.
Validation status
Deterministic components are cross-validated against R (mice);
imputation backends have unit, invariant, and numerical-diagnostic tests
plus a seeded simulation suite for bias and confidence-interval coverage
(pytest -m slow tests/simulation). See
docs/project-status.md for the canonical
per-feature maturity table — the backends are not claimed statistically
validated beyond what that table states.
Documentation
- docs/index.md — documentation home (build with
mkdocs serveafterpip install -e ".[docs]"); - Why impute the response? and MCAR, MAR, MNAR — concepts;
- Choosing an imputer, interpreting diagnostics, reporting an analysis — task guides;
- Mathematical foundations and validity conditions, assumptions A1–A8, GEE after imputation — theory;
- algorithm specifications — what the software actually computes, approximations included;
- worked examples — the epil count example and the external validation oracles.
Development
pip install -e ".[dev]"
pytest # fast suite
pytest -m slow tests/simulation -q # simulation studies
Rscript validation/r/rubin_reference.R # regenerate R pooling reference
longmi implements established missing-data theory (Rubin 1976, 1987; Barnard–Rubin 1999; Meng 1994; Wang–Robins 1998); it does not introduce a new proof of multiple imputation. See REFERENCES.md for sources and CITATION.cff to cite the software. MIT license.
Metadata
Release files for longmi 0.2.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| longmi-0.2.0a1.tar.gz | 125.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| longmi-0.2.0a1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 171.8 kB
Release files / longmi-0.2.0a1.tar.gz
| Download URL | longmi-0.2.0a1.tar.gz |
|---|---|
| Size | 125.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
812273780accc03c829f90b97182f62e4aba7058bc13b355bf80d2536351d8f8
|
|
BLAKE2b-256 checksum How to use checksums |
3dd1a44cf91c5d0dc8b6b0861234f2f351685c35a56af44fb8d2f01407eb4cf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 24, 2026.
Transparency logRelease files / longmi-0.2.0a1-py3-none-any.whl
| Download URL | longmi-0.2.0a1-py3-none-any.whl |
|---|---|
| Size | 46.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e145ff69b8160c83111b485d92c5852989bad57018f55f13ca69a418f022ab73
|
|
BLAKE2b-256 checksum How to use checksums |
2808f271897606e4fd65c32850dd592b9b5943323a3ca6061c1906b0880ea2a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 24, 2026.
Transparency log