Dividing each squared difference by its expected count puts the discrepancy in relation to the size of the expectation. A difference of the same absolute magnitude can therefore contribute differently depending on the expected frequency. After these standardized contributions are summed, the resulting chi-square statistic reflects the overall disagreement between the observed counts and the frequencies predicted under the null hypothesis.
The statistic alone does not determine the conclusion. Degrees of freedom describe the amount of information used when evaluating the result, while the p-value indicates how compatible the observed discrepancy is with the null hypothesis under that evaluation. Interpreting both allows researchers to judge whether the statistic reflects plausible random variation or evidence against the proposed model or relationship.
For a goodness-of-fit test, observed counts are compared with frequencies specified by a proposed distribution or model. For a test of independence, counts are examined across combinations of two categorical variables to assess whether an association is present. The calculation uses the same observed-versus-expected logic, but the question being tested changes.
Categories contribute according to the size of their squared observed-minus-expected difference after division by the corresponding expected count. Thus, a category or category combination with a substantial discrepancy relative to its expectation can make a strong contribution to the total statistic. Examining these individual contributions helps identify where the overall mismatch or apparent association is concentrated.
Begin by organizing the observed categorical counts and specifying the expected frequencies under the null hypothesis. Compute the contribution for each category or category combination, add those contributions to obtain the statistic, and then evaluate it using the appropriate degrees of freedom and p-value. This sequence connects the raw counts to a formal hypothesis-testing conclusion.
Use goodness-of-fit when the question concerns whether one categorical distribution matches a proposed set of frequencies. Use a test of independence when the goal is to evaluate a relationship between two categorical variables. In either case, the result can show whether deviations from the expected pattern are sufficiently inconsistent with the null hypothesis to provide evidence against it.