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 (
OptionalDistributionwithpset). 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
distso amissing_valueentry 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.
- composite_with_missing(dists, missing_value=MISSING)[source]
Build a
CompositeDistributionoverdistsin which every field toleratesmissing_value.Each field is wrapped with
marginalized(), so any field of an observation tuple may bemissing_valueand is integrated out of the likelihood (scoring and EM). Build the composite once and passMISSINGfor absent fields in your data – no per-field bookkeeping.
- marginalize_estimator_leaves(estimator, missing_value=MISSING)[source]
Wrap the leaf estimators of
estimatorso they marginalizemissing_value.Recurses through
CompositeEstimator(per field); every leaf estimator is wrapped in a marginalizingOptionalEstimator(est_prob=False-> no missingness rate is fit, the missing value is integrated out). Used bymixle.pplto fit a model from data with missing entries without imputing them.
- unwrap_marginalized(dist)[source]
Inverse of
marginalize_estimator_leaves()on a fitted distribution: strip the marginalizingOptionalDistributionwrappers (recursing throughCompositeDistribution) to recover the base model whose parameters were fit from the present entries.