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)
```
Metadata
Release files for CMH 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| CMH-1.0.1.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| CMH-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.0 kB
Release files / CMH-1.0.1.tar.gz
| Download URL | CMH-1.0.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ce5620c9fc82532e4bd64eaa3f40cd5b960fe0b0794a475e1381338465cd86f
|
|
BLAKE2b-256 checksum How to use checksums |
ba60eb47fef22209beeab109f012fecf7c87e1d6e1a49acafcb123146175d2a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / CMH-1.0.1-py3-none-any.whl
| Download URL | CMH-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81ff4877bef74df109bce90850365337a3187768aa1cb43ea8eadd37c49ab908
|
|
BLAKE2b-256 checksum How to use checksums |
e41d05c03da51a3d65048fa3c65fc70aa33ee3e11a68efbe9fb569f3c4cf80db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|