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 -e ".[analysis]"     # from a checkout; not yet on PyPI

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.1.0a1

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.1.0a1
File Size Uploaded
longmi-0.1.0a1.tar.gz 108.3 kB Details

Built distribution (wheel)

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

Total release size: 146.3 kB

Release files / longmi-0.1.0a1.tar.gz

Download URL longmi-0.1.0a1.tar.gz
Size 108.3 kB
Tags Source
SHA-256 checksum
How to use checksums
94177306126d67b34ab05b82249b0adf65f8c5af97eef37e14399c70c9a6356b
BLAKE2b-256 checksum
How to use checksums
a5b29281ecae89e5c7914ffc51afe8c76b3f3ac462ea37a8fda5a556e33080c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / longmi-0.1.0a1-py3-none-any.whl

Download URL longmi-0.1.0a1-py3-none-any.whl
Size 38.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abe720a3197849b03d2065b6b0acee9ee8105982a07ccae2c2a468520a2a9182
BLAKE2b-256 checksum
How to use checksums
8418c38fae3f5ea05cfe74e485df841ac2760c495be05bbfa68899f5c8de3024
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6
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