Contingency tables from grouped data

Contingency tables often arise from bivariate categorical data, but can also arise from univariate categorical data that is recorded separately from several groups.

The chi-squared test can also be used to test the hypotheses:

Null hypothesis (corresponding to independence)
The category probabilities are the same within each group.
Alternative hypothesis (corresponding to association)
Different groups have different probabilities.

Typhoid vaccines

Other examples

Two groups and two categories

In the special case where there are two groups and the categorical measurement has two categories (that we will call 'success' and 'failure'), the chi-squared test is testing whether the probability of success is the same in both groups. For example, in the Typhoid Vaccine data set, we are testing whether the probability of getting typhoid is the same for the groups getting the two vaccines.

This hypothesis can also be tested with a 2-sample test of equality of two proportions.

Fortunately, although the two tests have been motivated in a different way, it can be proved that:

The 2-sample test for equality of two proportions and the chi-squared test both result in the same p-value and conclusion.