cswork / libraryOpen practice workspace

Articles

Chi-Square Interview Questions: Expected Counts, Independence, and Practical Decisions

Practice Chi-Square interview questions with expected counts, independence, sparse cells, residuals, effect size, and practical decisions.

A Chi-Square result is easy to obtain and easy to misuse. An interviewer can hand you a contingency table, ask whether two categorical variables are independent, and then follow with the questions that matter: Where did the expected counts come from? Which cells drove the statistic? Are the observations independent? Is the effect large enough to change a product decision?

This guide answers those questions with one conversion-table exercise. It separates the test of independence from goodness of fit, calculates every expected count, handles sparse cells, and moves from a p-value to a practical recommendation.

For related practice in choosing a decision, population, and metric, use Clarify an Ambiguous Product Question and Define a Metric.

Evidence boundary: Formula and implementation claims below come from NIST and SciPy documentation. The conversion example, interview structure, and decision guidance are original preparation material.

What a strong interview answer must establish

Before calculating, answer five urgent questions:

  1. Are we testing independence in a contingency table or goodness of fit to specified proportions?
  2. What is one independent observation, and can the same unit appear more than once?
  3. How are expected counts constructed under the null hypothesis?
  4. Are expected counts large enough for the asymptotic reference distribution to be credible?
  5. What effect-size and cell-level evidence would change the business decision?

The article-specific thesis is: Chi-Square is a comparison between observed and null-expected counts, but a useful answer audits the data-generating unit and diagnoses the cells before interpreting statistical significance. A p-value alone does not reveal direction, magnitude, or operational value.

Independence and goodness of fit are different questions

A test of independence starts with two categorical variables measured on each observation. Examples include device type and conversion, plan tier and churn status, or region and support outcome. The null says the row and column variables are independent.

A goodness-of-fit test starts with one categorical variable and a specified distribution. It might ask whether traffic is allocated 50/50 across two variants or whether observed defect types follow historical proportions. The expected counts come from those prespecified probabilities, not from two sets of table margins.

Both tests use a Pearson statistic of the form

chi_square = sum((observed - expected)^2 / expected).

The models that produce expected differ. Mixing them can lead to a polished calculation for the wrong hypothesis.

This guide concentrates on independence.

Worked question: device type and conversion

Suppose 500 independent users each enter the analysis once. The table is:

DeviceConvertedDid not convertRow total
Mobile90210300
Desktop40160200
Column total130370500

The null hypothesis is that device type and conversion status are independent in this analyzed population. The alternative is that they are associated. This wording does not claim that device choice causes conversion; observational association may reflect user mix, acquisition source, geography, or other differences.

Under independence, the expected count in row i, column j is

E_ij = (row total_i * column total_j) / grand total.

For mobile converters, the expected count is 300 * 130 / 500 = 78. Applying the same calculation to every cell gives:

DeviceExpected convertedExpected not converted
Mobile78222
Desktop52148

Expected counts are model-based counts under the null. They are not forecasts, targets, or smoothed observations. Their row and column sums match the observed margins because those margins are used to construct them.

Calculate and explain the statistic

The four contributions are:

  • mobile converted: (90 - 78)^2 / 78 = 1.846;
  • mobile not converted: (210 - 222)^2 / 222 = 0.649;
  • desktop converted: (40 - 52)^2 / 52 = 2.769;
  • desktop not converted: (160 - 148)^2 / 148 = 0.973.

They sum to approximately chi_square = 6.237. For a two-by-two table, the degrees of freedom are (2 - 1)(2 - 1) = 1. The asymptotic p-value is about 0.013 without a continuity correction.

SciPy's chi2_contingency calculates the statistic, p-value, degrees of freedom, and expected frequencies. Its current documentation states that Yates' correction is applied by default when the degrees of freedom equal one, unless correction=False is supplied. An interviewer should state which version is being reported because the corrected and uncorrected answers differ.

The conclusion at a conventional 0.05 threshold is evidence against independence for this synthetic table. That sentence is deliberately narrow. It does not say device causes conversion, guarantee replication, or determine which product experience to ship.

Inspect residuals instead of stopping at the p-value

The Chi-Square statistic adds nonnegative cell contributions, so it hides direction. Pearson residuals recover it:

residual_ij = (observed_ij - expected_ij) / sqrt(expected_ij).

For mobile converters, the residual is positive because 90 exceeds 78. For desktop converters, it is negative because 40 is below 52. Squaring each Pearson residual yields that cell's contribution to the overall statistic.

NIST's independence-test documentation explicitly describes these standardized differences as a way to see cell contributions. For larger tables, a heatmap of signed residuals is more actionable than a single omnibus result. It identifies which category combinations deserve investigation, while multiple follow-up comparisons still require a controlled analysis plan.

Translate association into a practical effect

Mobile conversion is 90 / 300 = 30%; desktop conversion is 40 / 200 = 20%. The observed difference is 10 percentage points. That description supplies direction and a scale stakeholders can understand.

For an r x c table, Cramér's V is a common normalized association measure:

V = sqrt(chi_square / (n * min(r - 1, c - 1))).

Here, V = sqrt(6.237 / 500) ≈ 0.112. It summarizes association strength on a bounded scale, but generic labels such as small or medium do not substitute for product economics. A 10-point gap may be important, yet device-specific acquisition and experience differences could make a causal redesign ineffective.

A practical recommendation would be: verify that users are counted once and categories were defined before looking at the result; break down the gap by acquisition source or another prespecified confounder; then run or analyze an intervention capable of answering the causal question. The Chi-Square result prioritizes investigation. It does not by itself choose the intervention.

Expected-count rules require judgment

The familiar classroom rule says every expected cell should be at least five. NIST describes five as a threshold for its goodness-of-fit approximation, and SciPy calls it an often-quoted guideline for contingency tables. Treat it as a diagnostic for the approximation, not a law that can be repaired mechanically.

Three distinctions matter:

  • Check expected counts under the null, not only observed counts. An observed zero can coexist with an adequate expected count; a positive observed cell can still have a tiny expectation.
  • A large grand total does not guarantee adequate expected cells. A rare row crossed with a rare column can remain sparse.
  • Combining categories changes the question. Merge levels only when they are substantively interchangeable and the rule is defined without chasing significance.

If a two-by-two table is sparse, Fisher's exact test is a common conditional alternative. SciPy also documents Barnard's and Boschloo's exact tests. For broader two-way tables, current chi2_contingency supports permutation or Monte Carlo p-values under compatible settings. A sound answer selects a method based on the sampling scheme and table, rather than declaring one universal sparse-table fix.

Independence of observations is the deeper assumption

Expected counts can all exceed five while the analysis is still invalid. Suppose the 500 rows are sessions from 80 users, or orders from 20 stores. Repeated rows within a user or store are correlated. Feeding them into a simple contingency table as independent observations can make the apparent sample size and precision too large.

Possible repairs include aggregating to the randomization or sampling unit, modeling clustered outcomes, using a cluster-aware randomization test, or redesigning the analysis around unit-level categories. The correct choice depends on the estimand. “The software returned a p-value” is not evidence that the row structure matched the sampling model.

Also check mutual exclusivity and missingness. Each analyzed unit must have a well-defined category for both variables. Duplicated events, a catch-all category that mixes missing and real values, or treatment-affected inclusion can change the table before the test begins.

Common wrong answers and better repairs

Wrong answerWhy it failsBetter response
“Expected counts are the average of the cells.”Independence expectations preserve row and column margins.Use row total × column total ÷ grand total.
“A p-value below 0.05 means the variables are strongly related.”Significance depends on sample size and does not give magnitude.Report rates, residuals, and an effect measure such as Cramér's V.
“The result proves device causes conversion.”The test is associational unless design supports a causal claim.Name plausible confounding and the intervention or design needed.
“All observed cells exceed five, so assumptions pass.”The asymptotic diagnostic concerns expected counts, and dependence can still fail.Inspect expected cells and the independent unit.
“Merge rare categories until the p-value works.”Data-dependent merging changes the hypothesis and can hide structure.Merge only with a defensible, prespecified category definition.
“Run separate tests for every cell.”Unplanned follow-ups multiply false-positive opportunities.Use residuals diagnostically and control confirmatory comparisons.

A concise interview answer template

Begin: “I will define the table, null model, and independent unit before calculating expected counts.” Then:

  1. State whether the task is independence or goodness of fit.
  2. Show one expected-count calculation and verify all margins.
  3. Compute the statistic and degrees of freedom; name any continuity correction or resampling method.
  4. Inspect expected counts and the sampling unit.
  5. Use signed residuals and category rates to explain direction.
  6. Report practical magnitude and separate association from causation.
  7. Recommend the next decision, validation, or experiment.

This order makes the assumptions reviewable and prevents the p-value from becoming the entire answer.

Sources and Further Reading

Sources checked September 12, 2026. All conversion counts and conclusions in the worked example are synthetic.