Skip to main content

mechanism_viewer

mechanism_viewer is a Python package for exploring and diagnosing missing data mechanisms in tabular datasets.

It includes visualization tools, statistical diagnostics, imputation diagnostics, and synthetic data generation for investigating MCAR, MAR, and MNAR missingness.

Documentation: https://ti-n-a.github.io/mechanism_viewer/

Missing Data Mechanisms

There are 3 types of missing data mechanism, which are MCAR, MAR, and MNAR.

Missing Completely At Random (MCAR)

Missing values depend neither on observed variables nor on the missing values themselves.

Missing At Random (MAR)

Missing values depend on observed variables but do not depend on the missing values themselves.

Missing Not At Random (MNAR)

Missing values depend on the missing values themselves or on unobserved variables, but do not depend on the observed variables.

Project Structure

mechanism_viewer/
├── .github/                  # GitHub Actions workflows
├── mechanism_viewer/         # Package source code
│   ├── __init__.py
│   ├── _random.py
│   ├── _utils.py
│   ├── _validation.py
│   ├── accuracy_mar.py
│   ├── column_data_types.py
│   ├── dataset_generator.py
│   ├── little_mcar.py
│   ├── viewer_comparison.py
│   ├── viewer_correlation.py
│   ├── viewer_dendrogram.py
│   ├── viewer_imputation.py
│   ├── viewer_matrix.py
│   ├── viewer_simple.py
│   └── viewer_upset.py
├── tests/                    # Automated test suite
├── examples/                 # Reproducible package examples
├── use_cases/                # Real-world case studies
├── sample_data/              # Example datasets used by notebooks
├── docs/                     # MkDocs documentation source
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── mkdocs.yml
└── pyproject.toml

Installation

mechanism_viewer requires Python 3.10 or later.

  1. Install the package from PyPI:

    pip install mechanism_viewer
    
  2. Install documentation dependencies if necessary:

    pip install "mechanism_viewer[docs]"
    

Example

  1. Generate a synthetic dataset with missingness:

    from mechanism_viewer import (
        generate_dataset_with_missingness,
        plot_missing_rate,
        ColType)
    
    df = generate_dataset_with_missingness(
        n_rows=1000,
        type_array=[
            ColType.CONTINUOUS,
            ColType.CONTINUOUS,
            ColType.DISCRETE
        ],
        n_complete_cols=1,
        missing_mechanism_array=["MAR", "MCAR"],
        missing_rate_array=[0.20, 0.15])
    
    fig, ax = plot_missing_rate(df)
    fig.show()
    
  2. Run Little’s MCAR Test:

    from mechanism_viewer import (
        little_mcar_global,
        interpret_mcar_p_value)
    
    p_value = little_mcar_global(df)
    
    print(interpret_mcar_p_value(p_value))
    

Notebook Examples

  • Example notebooks demonstrating package usage are available inside examples/

  • Real-world use cases are available inside use_cases/

Sources of Use Case Datasets

The real-world examples in this repository use publicly available datasets from the following sources:

Contributing

Please read CONTRIBUTING.md for more information.

License

mechanism_viewer is distributed under the BSD 3-Clause "New" or "Revised" License. See LICENSE for details.

Limitations

Missing-data mechanisms generally cannot be proven using a single method.

The best practice is to combine multiple tools with domain knowledge.

This package should be used as supporting evidence rather than definitive proof of missing-data mechanisms.

Metadata

Release files for mechanism-viewer 0.1.1

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

Source distribution (sdist)

Source distribution for mechanism-viewer 0.1.1
File Size Uploaded Provenance Actions
mechanism_viewer-0.1.1.tar.gz 34.0 kB Without provenance Details for mechanism_viewer-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mechanism-viewer 0.1.1
File Interpreter ABI Platform Actions
mechanism_viewer-0.1.1-py3-none-any.whl Python 3 none any Details for mechanism_viewer-0.1.1-py3-none-any.whl

Total release size: 69.4 kB

Release files / mechanism_viewer-0.1.1.tar.gz

Download URL mechanism_viewer-0.1.1.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
30084257ddf99e22dfe61cf13763c4ffe93573f7272937f2d1d1f90841077d6f
BLAKE2b-256 checksum
How to use checksums
a238bcc65d1abfc8919bbf7af20d95a8c323c2c95ffd33f4dc127df3fbaf742e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / mechanism_viewer-0.1.1-py3-none-any.whl

Download URL mechanism_viewer-0.1.1-py3-none-any.whl
Size 35.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf445cceff9f86ddb4397e3e9ff4952d9c983a0c24c54ba845094ca09526e8d7
BLAKE2b-256 checksum
How to use checksums
97bfe086bb50dc1a1df0fca1a1d4d108f452c6a0e3879f01950d411f9de21fff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for mechanism-viewer 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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