Skip to content

Main content

Chi-Square Independence Statistic Calculator

Calculate Pearson's uncorrected independence statistic and expected counts for an RxC contingency table, without a p-value or small-sample validity claim.

Loading tool…

Description

Calculate Pearson's uncorrected independence statistic and expected counts for an RxC contingency table, without a p-value or small-sample validity claim.

A contingency table records counts for combinations of two categorical variables. Under independence, row and column margins determine expected counts. Pearson chi-square summarizes disagreement between observed and expected counts; its statistic is separate from a p-value or a decision about significance.1

Calculate Pearson's uncorrected independence statistic and expected counts for an RxC contingency table, without a p-value or small-sample validity claim.

When to use this tool

Use this tool to calculate chi square independence under the units, normalization, and boundary conventions below.

How to use the tool and how it works

  1. Supply observed in the field shapes below.
  2. Run the calculation. Correct format, shape, range, or undefined-statistic errors before interpreting a result.
  3. Read chiSquare, degreesOfFreedom, expected, total. Use the conventions below.

Sum observed nonnegative integer counts by row and column, set each expected count to rowTotal×columnTotal/grandTotal, and accumulate (observed−expected)²/expected. Return expected counts, the statistic, total and (rows−1)(columns−1) degrees of freedom.2

Input fieldMeaning and unitsAccepted input
observedObserved countsRequired. Array of Array of Safe integer; minimum 0.; minimum items 2; maximum items 32.; minimum items 2; maximum items 32.
Output fieldInterpretationReturned shape
chiSquarePearson statisticRequired. Finite number; minimum 0.
degreesOfFreedomDegrees of freedomRequired. Safe integer; minimum 1.
expectedExpected countsRequired. Array of Array of Finite number...
totalTotal countRequired. Safe integer; minimum 1.
json
{
  "input": {
    "observed": [
      [
        20,
        10,
        0
      ],
      [
        0,
        20,
        10
      ],
      [
        10,
        0,
        20
      ]
    ]
  },
  "output": {
    "chiSquare": 60,
    "degreesOfFreedom": 4,
    "expected": [
      [
        10,
        10,
        10
      ],
      [
        10,
        10,
        10
      ],
      [
        10,
        10,
        10
      ]
    ],
    "total": 90
  }
}

Limitations and assumptions

  • The table must be rectangular with positive row/column marginals and a safe-integer total. This is uncorrected Pearson independence chi-square: no Yates correction, p-value, sparse-cell remedy or independent-sampling verification is included.
  • The field tables state structural bounds; cross-field constraints and bounded search or output budgets also apply. Unknown keys are rejected where the object contract disallows them. Input errors are distinct from null fields and deliberate invalid controls in a successful output.

Alternative or Complementary methods

Choose the statistic according to the question and data conventions. Inspect the supplied series or matrix and the stated assumptions before comparing outputs from implementations with different defaults.

References

  1. SciPy: contingency-table independence and expected frequencies — SciPy

  2. Tool behavior and example: Chi-Square Independence Statistic Calculator — tool.io

Similar or alternative tools

  • chi square goodness of fit

    Test how well observed category counts fit an expected distribution.

  • explicit edge count table

    Count explicit observations in supplied ordered histogram bins with final edge included, reporting outside count without clamping under/overflow into endpoint bins.