Skip to main content

Chi-square test with Monte Carlo simulation

Project description

chi2sim

Chi-square test with Monte Carlo simulation for contingency tables. The package and its documentation are still under construction.

Description

The chi2sim package is a Python implementation that contains the translation of R's H tests for contingency tables when simulate.p.value = TRUE, originally written in C and based on Patefield's (1981) FORTRAN algorithm. The package provides a fast and reliable method to compute p-values for chi-square tests using Monte Carlo simulation.

Installation

pip install chi2sim

Usage

import numpy as np
from chi2sim import chi2_cont_sim

# Example contingency table
table = np.array([
    [10, 5],
    [20, 15]
], dtype=int)

# Perform chi-square test with Monte Carlo simulation
result = chi2_cont_sim(table)
print(result)

Features

  • Similar to SciPy's scipy.stats.chi2_contingency, but returns
  • Monte Carlo simulation for p-value approximation
  • Easy-to-use Python interface

Requirements

  • Python >= 3.9
  • NumPy >= 1.15.0

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use the chi2sim package in your study, please don't forget to cite the following literatures:

  • Hope, A. C. A. (1968). A simplified Monte Carlo significance test procedure. Journal of the Royal Statistical Society Series B, 30, 582–598. doi:10.1111/j.2517-6161.1968.tb00759.x.

  • Patefield, W. M. (1981). Algorithm AS 159: An efficient method of generating r x c tables with given row and column totals. Applied Statistics, 30, 91–97. doi:10.2307/2346669.

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

chi2sim-1.0.2.1.tar.gz (72.6 kB view details)

Uploaded Source

Built Distribution

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

chi2sim-1.0.2.1-cp311-cp311-win_amd64.whl (100.5 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file chi2sim-1.0.2.1.tar.gz.

File metadata

  • Download URL: chi2sim-1.0.2.1.tar.gz
  • Upload date:
  • Size: 72.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for chi2sim-1.0.2.1.tar.gz
Algorithm Hash digest
SHA256 e010e11a9a3e4c0977e28e9c48929a30478964b39655e073f0f2a0161436b63a
MD5 1eeca82f0e173ff26a44c277c0871e37
BLAKE2b-256 1b2956127c5835ade5ce305ef8b7595edcba84ee6ca3f6bdfd5238292e6e9476

See more details on using hashes here.

File details

Details for the file chi2sim-1.0.2.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: chi2sim-1.0.2.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 100.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for chi2sim-1.0.2.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a2a6b71d4652152114a955e333a37527468514f323e2bc5e0998750fae70442b
MD5 6a9077740b909b1a4b25090db85a1017
BLAKE2b-256 2b34007f679ea7216b55e81df033bcfafdfe08a176f62f80d7e217dbecc29d13

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