Skip to main content
Pre-release

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 — LongitudinalData validates 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) and NegativeBinomialImputer (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, and CallableAnalysis for custom estimators.
  • Pooling — pool_rubin, multivariate, bit-compatible with mice::pool.scalar (verified at 1e-12 against R), Barnard–Rubin degrees of freedom, fraction of missing information, and validity_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

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.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for longmi 0.2.0a2
File Size Uploaded
longmi-0.2.0a2.tar.gz 150.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for longmi 0.2.0a2
File Interpreter ABI Platform
longmi-0.2.0a2-py3-none-any.whl Python 3 none any Details

Total release size: 197.4 kB

Release files / longmi-0.2.0a2.tar.gz

Download URL longmi-0.2.0a2.tar.gz
Size 150.4 kB
Tags Source
SHA-256 checksum
How to use checksums
697edf54008cdb2704595bd991f2a427b5b51129d7346444550c095adb42dcb1
BLAKE2b-256 checksum
How to use checksums
bf1bc10046353076fc410efd72ca926a8c3ed30194a79137378f02deb096559e
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 27, 2026.

Transparency log

Release files / longmi-0.2.0a2-py3-none-any.whl

Download URL longmi-0.2.0a2-py3-none-any.whl
Size 47.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6839ac8f4a198d65349349e2f9f6d69605808ff71b86a120a93015b5025a6fa1
BLAKE2b-256 checksum
How to use checksums
416243334062c2016d66a6e9311beed035435e541175413210c687b67b0f58d8
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 27, 2026.

Transparency log
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