Skip to main content

Simple statistical assumption checks for ANOVA, linear regression, and logistic regression.

Project description

assumpcheck

assumpcheck is a small Python package for checking core assumptions for:

  • ANOVA
  • Linear regression
  • Logistic regression

The package is designed to stay simple:

  • concise terminal output by default
  • plots only when they matter
  • mitigation suggestions when something fails
  • optional structured output for programmatic use

Installation

pip install assumpcheck

Once the package is published on PyPI, the installation target will become:

pip install assumpcheck

The package currently depends on:

  • numpy
  • pandas
  • scipy
  • statsmodels
  • matplotlib

Public API

from assumpcheck import (
    check_anova,
    check_linear_regression,
    check_logistic_regression,
)

ANOVA

report = check_anova(y=y, groups=groups)

Linear regression

report = check_linear_regression(model=fitted_ols_model)

Logistic regression

report = check_logistic_regression(model=fitted_logit_model)

Quickstart

import numpy as np
import pandas as pd

from assumpcheck import check_linear_regression

rng = np.random.default_rng(27)
X = pd.DataFrame(
    {
        "x1": rng.normal(size=35),
        "x2": rng.normal(size=35),
    }
)
y = 1.0 + 1.8 * X["x1"] - 0.6 * X["x2"] + rng.normal(scale=0.35, size=35)

report = check_linear_regression(
    X=X,
    y=y,
    design_independent=True,
    plots_on_fail=False,
)

Typical output looks like:

LINEAR REGRESSION ASSUMPTION CHECKS
[PASS] Linearity
[PASS] Independence
[PASS] Normality of residuals
[PASS] Homoscedasticity
[PASS] Multicollinearity
[WARN] Extreme influential points

Summary: 5 pass, 1 warn

Example output

ANOVA ASSUMPTION CHECKS
[INFO] Independence
[PASS] Normality of residuals
[PASS] Equal variance across groups
[FAIL] Extreme outliers

Summary: 2 pass, 1 fail, 1 info

Details:
- Extreme outliers [FAIL]
  Metric: Max |standardized residual| = 3.420; flagged points > 3: 1
  Threshold: Values above 2 deserve review and values above 3 are concerning.
  Interpretation: At least one observation has a standardized residual above the common concern threshold.
  Possible mitigation:
    - Verify data entry for flagged cases.
    - Check whether the observation is legitimate but unusual.
    - Consider a transformation, robust method, or nonparametric alternative if outliers remain influential.

Options

All three public functions support these core options:

  • alpha=0.05
  • show_all=False
  • plots_on_fail=True
  • verbose=False
  • return_dict=False
  • design_independent=None

Additional model-specific option:

  • check_linear_regression(..., ordered=False)

Output behavior

Default behavior:

  • prints a concise summary
  • shows plots for failed or warning-level checks if plots_on_fail=True
  • returns an AssumptionReport object

Optional behavior:

  • verbose=True prints detail for every check
  • show_all=True prints all details and shows all available plots
  • return_dict=True returns a serializable dictionary

Independence handling

By default, independence is treated as a design question:

  • design_independent=None gives an INFO result
  • design_independent=True gives a PASS unless an ordered linear model also shows autocorrelation warnings
  • design_independent=False gives a FAIL

Current checks

ANOVA

  • Independence
  • Normality of residuals
  • Equal variance across groups
  • Extreme outliers

Linear regression

  • Linearity
  • Independence
  • Normality of residuals
  • Homoscedasticity
  • Multicollinearity
  • Extreme influential points

Logistic regression

  • Linearity in the log-odds
  • Independence
  • Multicollinearity
  • Extreme influential points
  • Adequate sample / no separation
  • Model fit summary via ROC / AUC

Notes on the MVP

  • The package prioritizes statsmodels models first.
  • Thresholds are intentionally presented as heuristics.
  • Logistic ROC / AUC is treated as a fit diagnostic, not a strict assumption.
  • Some diagnostics need access to original data or design metadata to be fully informative.
  • The current influence heuristics are intentionally conservative, so clean linear or logistic examples may still emit a WARN.

Examples

  • Script: examples/basic_usage.py
  • Notebook: examples/assumpcheck_examples.ipynb

To rebuild the executed notebook and example plot assets:

python examples/build_workflow_artifacts.py

Tests

Run the test suite with:

python -m pytest -q

Release Process

For the first public release to TestPyPI and PyPI using GitHub Trusted Publishing, see RELEASING.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assumpcheck-0.1.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

assumpcheck-0.1.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file assumpcheck-0.1.1.tar.gz.

File metadata

  • Download URL: assumpcheck-0.1.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for assumpcheck-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a23070f2c88a1c1a370394a615de537f84e83ce233289bfb0451b353d4348a9a
MD5 10b2f24afccaab3882d1a08396c8c87c
BLAKE2b-256 6fbb17a4ad44690f103a1fe1375155c9743094707aefda70d14a03a0d94bff56

See more details on using hashes here.

File details

Details for the file assumpcheck-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: assumpcheck-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for assumpcheck-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa30e5122b2cdc5daf0f37ba8da7d9cf07d5202df1ab246dcc09adc00ac3b440
MD5 47b5b7dfc83584d7a5526917465fbbc3
BLAKE2b-256 b3a1d69634cb7c70f3f5209e3ef72453a9a0575df3ebacb5c45bd6cfe3a93e98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page