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.tar.gz (72.5 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-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.tar.gz.

File metadata

  • Download URL: chi2sim-1.0.2.tar.gz
  • Upload date:
  • Size: 72.5 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.tar.gz
Algorithm Hash digest
SHA256 001f11a24cc019249d673b40cfe1f28f07c0784bb8d20cfe654d109c58a41646
MD5 2f08b2c067ed0a09066a3dc2790fc247
BLAKE2b-256 8a49ba685c907a0f7beba794e55ec4115b3727ff4185bceb07f9f05e58abaf46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chi2sim-1.0.2-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-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 35055320e3059e110eacc09ed059fff45b09578158902060f12b22d3fae355b0
MD5 fe339ca4c5f08dae9e67bb420ca5c63e
BLAKE2b-256 929a116baa557d520bc7c7a71da017bfd5d3d1e6cc24755b9670df8cbe67ac79

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