Mechanisms
Installation | Core concepts | Mechanisms | Patterns | Mathematical details | Benchmarking workflow | API reference
Mechanisms describe the relationship between the data and the probability that a value is missing.
For full formulas, normalization rules, and sampling details, see Mathematical details.
MCAR
mcar means Missing Completely At Random. Every eligible position has the same
chance of being masked, independent of values in the array.
X_missing, mask = simulate_missingness(X, "mcar", 0.15, seed=42)
MCAR samples without replacement, so the achieved missing count is exact up to rounding.
Parameters:
Parameter |
Default |
Description |
|---|---|---|
|
|
Dimensions to mask, or |
MAR
mar means Missing At Random. Missingness depends on observed driver
dimensions, not on the value being masked. By default, MAR masks non-driver
dimensions only, so driver_dims=[0] uses dimension 0 to drive missingness in
the other dimensions while leaving dimension 0 observed.
X_missing, mask = simulate_missingness(
X, "mar", 0.25, seed=42,
driver_dims=[0], strength=2.0
)
With multiple driver dimensions, driver_weights controls their relative
contribution. Weights are normalized automatically.
X_missing, mask = simulate_missingness(
X, "mar", 0.25, seed=42,
driver_dims=[0, 1],
driver_weights=[0.8, 0.2],
strength=2.0
)
If a driver value is already NaN, TSGap ignores that value when constructing
the driver signal. Timesteps with no observed driver value receive a neutral
driver score after normalization, so pre-existing driver gaps do not turn the
missingness probability into NaN or collapse the requested target rate. If all
selected driver dimensions are entirely NaN, MAR raises a clear ValueError.
If target is provided explicitly, it must not overlap driver_dims. Masking a
driver dimension according to its own value is self-dependent missingness, which
is MNAR/hybrid behavior for that dimension rather than strict MAR. To request
that behavior intentionally, pass allow_self_masking=True.
For one-feature arrays, the default MAR configuration raises a clear error because there is no separate observed driver that can explain missingness in a target variable.
Parameters:
Parameter |
Default |
Description |
|---|---|---|
|
|
Dimensions that drive missingness |
|
|
Optional non-negative weights for drivers |
|
non-driver dimensions |
Dimensions to mask, or |
|
|
Dependency strength, must be non-negative |
|
|
Minimum probability floor |
|
|
|
|
|
Permit target/driver overlap for explicit hybrid behavior |
MNAR
mnar means Missing Not At Random. Missingness depends on the value itself.
X_missing, mask = simulate_missingness(
X, "mnar", 0.20, seed=42,
mnar_mode="extreme", strength=3.0
)
Modes:
Mode |
Effect |
|---|---|
|
High values are more likely to be missing |
|
Low values are more likely to be missing |
|
Values far from the mean are more likely to be missing |
Parameters:
Parameter |
Default |
Description |
|---|---|---|
|
|
|
|
|
Dimensions to mask, or |
|
|
Dependency strength, must be non-negative |
Rate Calibration
MAR and MNAR use a logistic probability model and calibrate an offset by binary search so the expected missing rate over eligible positions matches the target rate. Because they sample Bernoulli outcomes, achieved rates are approximate and vary more on small arrays.