ARBIMETRA · Financial intelligence, made practical.

ARBIMETRA LAB

Chi-square Test

Tests whether categories follow an expected pattern, or whether two categorical variables are associated.

What it does

Tests whether categories follow an expected pattern, or whether two categorical variables are associated.

Use it with counts of categories.

Data you need

  • One or two categorical variables

Optional: Expected proportions

Supported data: Categorical. Level: Beginner.

Formula and method

χ² = Σ(O−E)²/E

Expected counts come from the stated proportions for goodness-of-fit, or from row and column totals for independence. Squared differences between observed and expected counts, scaled by expected counts, are summed and compared with a chi-square distribution.

Assumptions

  • Observations are independent
  • Expected counts are not too small

Input checks

  • Warnings when expected counts fall below 5

How to read the result

Compare observed and expected counts to see what drives the result.

Worked example

Illustrative run on Simulated study data (teaching data). These figures are the actual output of this model on that example, and they say nothing about your own data.

  • Chi-square = 4.8282, df = 2, p = 0.0894.
  • The association is not statistically significant at the 5% level.

Limitations

  • Association does not establish causation

Numerical validation

Validated 17 of 17 automated checks passed, including numerical results, invalid input, missing values, small samples, constant variables, charts and the interpretation text.

CheckReferenceResultAbs. errorToleranceSource
Goodness of fit by hand11.611.60.0e+01e-12Hand calculation
p-value0.040699390.040699390.0e+01e-11SciPy
Independence by hand6.651583716.651583710.0e+01e-11Independent NumPy calculation

Computed with python 3.13.2, numpy 2.2.5, scipy 1.14.1, pandas 2.3.3, statsmodels 0.14.4, scikit-learn 1.7.0, in your browser. A passing check confirms the listed comparison only. It does not make any result suitable for your data, and it is not a claim of equivalence with other statistical software.

Questions

What if expected counts are small?

The chi-square approximation can fail. Combine categories or use an exact test.

ARBIMETRA LAB is an educational and research tool. Results should be checked by the researcher and are not professional advice.