mixle.stats.missing module

First-class handling of occasional missing entries by MARGINALIZATION (MAR/MCAR), plus the MISSING sentinel.

Two ways to cope with an absent entry:

  • Model it – learn a probability that the entry is missing (OptionalDistribution with p set). Appropriate when missingness is informative and you want to estimate its rate.

  • Marginalize it – integrate the missing coordinate out of the likelihood so it contributes nothing. A missing field then has log-density 0 and yields no sufficient statistics, so EM fits each field from its present rows only – the maximum-likelihood estimator under missing-at-random. This is the elegant default for “occasional missing entries”: you don’t model a nuisance missingness rate, and you can still read posteriors over the unobserved coordinates given the observed ones.

Marginalization is exactly OptionalDistribution(dist, p=None); this module surfaces it as a first-class tool with a canonical sentinel and ergonomic builders (so you don’t wrap every field by hand), and pairs with CompositeDistribution.marginal/condition and MixtureDistribution.conditional to get the posterior/imputation over the missing entries (see those methods).

marginalized(dist, missing_value=MISSING)[source]

Wrap dist so a missing_value entry is marginalized out (not modeled).

The wrapped field contributes log-density 0 and no sufficient statistics for missing observations, so estimation uses only the present ones. Equivalent to OptionalDistribution(dist, p=None, missing_value=missing_value) – this is the principled missing-at-random treatment, not a degenerate case.

Parameters:
  • dist (Any)

  • missing_value (Any)

Return type:

Any

composite_with_missing(dists, missing_value=MISSING)[source]

Build a CompositeDistribution over dists in which every field tolerates missing_value.

Each field is wrapped with marginalized(), so any field of an observation tuple may be missing_value and is integrated out of the likelihood (scoring and EM). Build the composite once and pass MISSING for absent fields in your data – no per-field bookkeeping.

Parameters:
Return type:

Any

marginalize_estimator_leaves(estimator, missing_value=MISSING)[source]

Wrap the leaf estimators of estimator so they marginalize missing_value.

Recurses through CompositeEstimator (per field); every leaf estimator is wrapped in a marginalizing OptionalEstimator (est_prob=False -> no missingness rate is fit, the missing value is integrated out). Used by mixle.ppl to fit a model from data with missing entries without imputing them.

Parameters:
  • estimator (Any)

  • missing_value (Any)

Return type:

Any

unwrap_marginalized(dist)[source]

Inverse of marginalize_estimator_leaves() on a fitted distribution: strip the marginalizing OptionalDistribution wrappers (recursing through CompositeDistribution) to recover the base model whose parameters were fit from the present entries.

Parameters:

dist (Any)

Return type:

Any