ForHosting KIT · Math

Chi-square independence test calculator

A 2×2 table of 100 observations can give a chi-square of 4 on 1 degree of freedom and a p-value of about 0.0455, below the usual 0.05. Enter your observed counts to see expected counts and margins as well. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

A chi-square test of independence asks whether two categorical factors in a contingency table are associated or whether the row and column classifications could have arisen under independence. Students, analysts, and automated grading pipelines need a deterministic oracle that turns observed cell counts into Pearson’s χ², the correct degrees of freedom, and a two-sided-style upper-tail p-value without silently inventing expected frequencies when a margin is zero. This chi-square independence test calculator accepts a matrix of non-negative observed counts, builds row and column totals, forms expected counts as the product of margins over the grand total, sums (O−E)²/E over every cell, and reports df equals (rows−1) times (columns−1) with the corresponding χ² survival probability.

What the chi-square independence test computes

Pearson’s chi-square test of independence starts from an r-by-c contingency table of observed non-negative counts O_ij. Row totals R_i and column totals C_j and the grand total N are formed by summing the table. Under the null hypothesis that row and column classifications are independent, the expected count in cell (i,j) is E_ij equals R_i times C_j divided by N.

The test statistic is the sum over all cells of (O_ij minus E_ij) squared divided by E_ij. When the null is true and expected counts are not too small, that statistic is approximately chi-square distributed with degrees of freedom (r−1)(c−1). The p-value reported here is the upper-tail probability P(χ²_df greater than the observed statistic), which is the usual significance measure for this test.

A small p-value suggests that the observed association between rows and columns is unlikely under independence alone. The calculator does not apply continuity corrections, Yates adjustments, or Fisher exact procedures; it implements the classical Pearson formula so results match textbook worked examples and most software defaults for the uncorrected independence test. Always interpret significance against your prechosen alpha and against sample-size caveats: very large N can make tiny associations statistically significant, and sparse tables with many expected counts below five may need exact methods instead.

Who uses a chi-square independence check

Classrooms and tutoring platforms use a chi-square independence test calculator so learners can check χ², df, and p against hand calculations on arbitrary 2×2 and larger tables without sign errors in the expected-count step. Exam generators and LMS plugins need a deterministic oracle that rejects zero-margin tables instead of returning NaN or an empty success body that a buggy grader might treat as a pass.

Product analytics, A/B dashboards, and survey tools often cross-tabulate two categorical factors—device type by conversion, region by preference, treatment by outcome—and want a lightweight parse call rather than spinning up a full statistics stack for a single contingency matrix. Failed validation does not consume balance.

Classroom and homework checks

Let students paste a contingency table and verify Pearson’s χ², degrees of freedom, and p-value against textbook independence examples.

Exam and LMS auto-grading

Mark chi-square independence items with a deterministic oracle that rejects zero margins and never invents expected counts.

Survey and product cross-tabs

Test association between two categorical factors in dashboards or notebooks without importing a full statistics library for one table.

How do I run a chi-square test of independence?

Send a nested array table of non-negative observed counts with at least 2 rows and 2 columns.

What happens if a row or column margin is zero?

A zero margin makes expected counts zero or undefined, so the classical (O−E)²/E sum is not defined and is not billed.

Are zero cells allowed inside the table?

Yes. Individual cells may be zero. Only an entire zero row or entire zero column (or an all-zero table) is rejected.

Does the calculator apply the Yates continuity correction?

No. It uses the classical Pearson formula without continuity or Yates corrections and without Fisher's exact test, so the results match textbook worked examples and the uncorrected test most software runs by default.

When are expected counts too small for this test?

When many expected counts fall below five, the chi-square approximation becomes unreliable and an exact method may be the better choice. Very large totals carry the opposite risk: tiny associations can still come out statistically significant.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/stat/chi-square-independence

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/stat/chi-square-independence \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"table":[[20,30],[30,20]]}'
{
  "table": [
    [
      20,
      30
    ],
    [
      30,
      20
    ]
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "stat.chi_square_independence",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Zero cells are allowed; a zero row or column margin fails with invalid_input because expected counts would be undefined.

Input contract, margins, response fields, and errors

At least two rows and two columns are required so degrees of freedom are positive. Maximum dimensions are forty by forty to keep the free parse path bounded. Zero cells are permitted and contribute normally to the sum whenever the corresponding expected count is positive. An all-zero table fails because the grand total is zero. POST a JSON body with the required field table: a nested array of rows, each row an array of finite non-negative numbers sharing the same column count. You may also send the same matrix under the aliases matrix, contingency_table, or observed, or as a JSON string of the nested array. Every cell must be non-negative; negative counts are rejected as invalid_input naming the cell index. On success the response echoes rows, cols, and grand total n; chi_square rounded for stable goldens; integer df; p_value; a boolean significant_05 that is true when p_value is strictly less than 0.05; the row_totals and col_totals vectors; the full expected matrix; and a short formula string restating the Pearson identity. Example: table [[20,30],[30,20]] yields chi_square four, df one, and a p-value near 0.0455, so significant_05 is true. Pair the numeric result with your own domain labels for rows and columns; this endpoint does not store category names.

Where a contingency chi-square API earns its keep

Keep tables modest, pin rounded chi_square and p_value in tests, and you get reproducible independence tests for homework, research notebooks, and edge workers without standing up R or SciPy solely for Pearson’s contingency statistic.

How is the p-value computed?

p_value is the upper-tail probability of a chi-square random variable with df degrees of freedom evaluated at the Pearson statistic, via the regularized incomplete gamma function.

What does the chi-square independence test calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →