mechanism_viewer
mechanism_viewer is a python package that can be used to help diagnose the missing data mechanism of a dataset.
It includes visualization tools, statistical testing, imputation tools, and synthetic dataset generation.
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/
│
├── dataset_generator.py
├── viewer_simple.py
├── viewer_matrix.py
├── viewer_upset.py
├── viewer_comparison.py
├── viewer_correlation.py
├── viewer_dendrogram.py
├── viewer_imputation.py
├── little_mcar.py
├── accuracy_mar.py
├── column_data_types.py
├── _validation.py
├── _utils.py
└── _random.py
Installation
-
Clone the repository:
git clone https://github.com/Ti-n-a/mechanism_viewer.git cd mechanism_viewer
-
Create a virtual environment.
Create a python virtual environment:
python -m venv .venv source .venv/bin/activate
Or create a conda environment:
conda create -n mechanism-viewer python=3.11 conda activate mechanism-viewer
-
Install the package:
pip install -e .
-
Install documentation dependencies if necessary:
pip install -e ".[docs]"
Example
-
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()
-
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:
-
- Used in:
use_cases/cancer.ipynb
- Used in:
-
- Used in:
use_cases/student.ipynb
- Used in:
-
- Used in:
use_cases/contraceptive.ipynb
- Used in:
-
- Used in:
use_cases/diabetes.ipynb
- Used in:
-
- Used in:
use_cases/horses.ipynb
- Used in:
Contributing
Please read CONTRIBUTING.md for more information.
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mechanism_viewer-0.1.0.tar.gz | 33.7 kB | Without provenance | Details for mechanism_viewer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mechanism_viewer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mechanism_viewer-0.1.0-py3-none-any.whl |
Total release size: 69.0 kB
Release files / mechanism_viewer-0.1.0.tar.gz
| Download URL | mechanism_viewer-0.1.0.tar.gz |
|---|---|
| Size | 33.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcf6c800a74669d14739d2b43b0e82205b357173ed47db313137726f9eefc919
|
|
BLAKE2b-256 checksum How to use checksums |
0ef5c6310162f16dff49e74ae22e8e3ca9f1c03a3722b41e32b2368615f40e36
|
| 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.0-py3-none-any.whl
| Download URL | mechanism_viewer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85b14ffcadd16a377ec352fa68b611a60f5eedd3011a3f3bdc380553e108b192
|
|
BLAKE2b-256 checksum How to use checksums |
db9933e443ebf6c06120c23ae3714cfc60285b224fcfebe72f4c1abaca71e298
|
| 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.0
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.