This is a simple Python script that demonstrates how to perform a chi-square test using a statistical approach. The script takes two input CSV files: one containing the observed frequencies and one containing the expected frequencies. It then calculates the chi-square statistic and the corresponding p-value, and outputs the results to the console.
- Python 3.x
- NumPy
- Pandas
- Clone this repository or download the
chisquare.py
file. - Install the required packages using pip:
pip install numpy pandas
- Prepare two CSV files with the observed and expected frequencies. The CSV files should have a single column each, and the same number of rows.
- Run the script with the following command:
python chisquare.py path/to/observed.csv path/to/expected.csv
Example: python chisquare.py data/observed.csv data/expected.csv
This code is released under the MIT License. See the LICENSE
file for more information.
This script was inspired by the following resources:
- Chi-squared Test for Independence in Python by Will Koehrsen
- Using Chi-Square Statistic in Research by Scribbr