Skip to main content

CMH

Implementation of the Cochran-Mantel-Haenzsel Chi2 Test, based on/ported from "Categorical Data Analysis", page 295 by Agresti (2002) and R implementation of the function mantelhaen.test().

Usage

import pandas as pd
from cmh import CMH

df = pd.DataFrame(
    [
        ['S1', 'no', 'yes'],
        ['S1', 'no', 'yes'],
        ['S1', 'no', 'yes'],
        ['S1', 'no', 'yes'],
        ['S1', 'no', 'yes'],
        ['S1', 'no', 'yes'],
        ['S1', 'yes', 'yes'],
        ['S1', 'yes', 'yes'],
        ['S1', 'yes', 'yes'],
        ['S1', 'yes', 'yes'],
        ['S1', 'yes', 'yes'],
        ['S1', 'yes', 'yes'],

        ['S2', 'yes', 'yes'],
        ['S2', 'yes', 'yes'],
        ['S2', 'yes', 'yes'],
        ['S2', 'yes', 'yes'],
        ['S2', 'yes', 'yes'],
        ['S2', 'no', 'yes'],
        ['S2', 'no', 'yes'],
        ['S2', 'no', 'yes'],
        ['S2', 'no', 'yes'],
        ['S2', 'no', 'no'],
        ['S2', 'no', 'no'],
        ['S2', 'no', 'no'],
        ['S2', 'no', 'no'],

    ],
    columns=['stratum', 'A', 'B']
)

# CMH() will automatically count frequencies of the columns in the dataframe.
result = CMH(df, 'A', 'B', stratifier='stratum')
print(result)

# Will print:
#
#         Cochran-Mantel-Haenszel Chi2 test
#
# "A" x "B", stratified by "stratum"
#
# Cochran-Mantel-Haenszel M^2 = 3.33333, dof = 1, p-value = 0.0679

# Individual components of the result can be accessed via attributes:
print(result.dof)
print(result.p)

# If you're working in a Jupyter Notebook, you can also use `display()` for
# a nicely formatted result.
display(result)

```

Download files

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

Source Distribution

CMH-1.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

CMH-1.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file CMH-1.0.1.tar.gz.

File metadata

  • Download URL: CMH-1.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for CMH-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5ce5620c9fc82532e4bd64eaa3f40cd5b960fe0b0794a475e1381338465cd86f
MD5 6a6f4a21d7260e292ae8394e93977d9a
BLAKE2b-256 ba60eb47fef22209beeab109f012fecf7c87e1d6e1a49acafcb123146175d2a4

See more details on using hashes here.

File details

Details for the file CMH-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: CMH-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for CMH-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81ff4877bef74df109bce90850365337a3187768aa1cb43ea8eadd37c49ab908
MD5 f5c537b1e3dc75c67a6121090bd7171d
BLAKE2b-256 e41d05c03da51a3d65048fa3c65fc70aa33ee3e11a68efbe9fb569f3c4cf80db

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

Supported by

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