Crosstab Analysis and the Chi-Square Test
Crosstab analysis organizes counts and proportions for each combination in a table, and the chi-square test decides whether those differences are statistically significant.
Do men and women prefer different products? Do the shopping channels people mainly use differ by age group? What is the relationship between education level and employment status?
The standard methods for checking how two categorical variables are related, as in these questions, are crosstabulation and the chi-squared test.
Crosstab analysis organizes counts and proportions for each combination of two variables in a table. The chi-square test decides whether the differences that appear are statistically significant. The two methods play different roles, but in real surveys and statistical analyses they are often used together.
They are especially useful for analyzing data divided into categories, such as gender, age group, occupation, product preference or purchase experience. In this article, we look at crosstab analysis and the chi-square test from their basic concepts through a real example, how to interpret the results table, effect sizes and what to check before the analysis.
What is crosstab analysis?
Crosstab analysis combines two or more categorical variables to check the frequency and proportion of data falling in each category.
The results are usually shown in a form called a crosstab or contingency table. For example, suppose you surveyed 200 customers about their gender and whether they prefer online shopping.
Gender is divided into men and women, and online shopping preference into 'prefer' and 'do not prefer.' Organizing the collected data in a contingency table gives the following.
| Gender | Prefer online shopping | Do not prefer | Total |
|---|---|---|---|
| Men | 60 | 40 | 100 |
| Women | 40 | 60 | 100 |
| Total | 100 | 100 | 200 |
The table shows that 60 of 100 men preferred online shopping, while 40 of 100 women preferred it. In other words, the rate of preferring online shopping was 60% for men and 40% for women. Crosstab analysis shows that the response distributions of the two groups differ.
But an important question remains.
Is the observed 20-percentage-point difference statistically significant?
To answer this question, you can use the chi-square test.
How is crosstab analysis different from frequency analysis?
To understand crosstab analysis, it helps to first know how it differs from frequency analysis.
Frequency analysis checks how often each value appears in a single variable. Crosstab analysis, by contrast, combines two or more variables to compare distributions by category. For example, suppose you surveyed 200 customers about their preferred shopping channel.
Frequency analysis
| Shopping channel | Respondents | Share |
|---|---|---|
| Online | 100 | 50% |
| In-store | 100 | 50% |
| Total | 200 | 100% |
Frequency analysis shows that half of all customers prefer online shopping. But it cannot tell you which customers prefer online shopping.
Crosstab analysis
| Gender | Online | In-store |
|---|---|---|
| Men | 60% | 40% |
| Women | 40% | 60% |
Crosstab analysis lets you see how shopping channel preferences differ by gender. In other words, if frequency analysis shows the distribution of one variable, crosstab analysis shows the distribution across combinations of several variables.
| Aspect | Frequency analysis | Crosstab analysis |
|---|---|---|
| Main purpose | Check the distribution of a single variable | Compare distributions across variable combinations |
| Typical output | Frequencies, percentages | Contingency table, row and column percentages |
| Example question | How many people prefer online shopping? | Does the rate of preferring online shopping differ by gender? |
| Main use | Understanding overall responses | Exploring response differences between groups |
Both analyses can be used as descriptive statistical methods for summarizing and understanding data.
Which percentages should you look at in a contingency table?
One thing to watch in crosstab analysis is the basis on which percentages are calculated.
Even for the same contingency table, what you are describing changes depending on whether you use row or column percentages. Typically you can look at row percentages, column percentages and total percentages.
Row percentage
Row percentages are calculated based on each row's total. If gender is set as the row in the earlier example, they look like this.
| Gender | Prefer online shopping | Do not prefer |
|---|---|---|
| Men | 60% | 40% |
| Women | 40% | 60% |
This table shows the share preferring online shopping within each gender group. So it suits the question, 'How do men's and women's shopping channel preferences differ?'
Column percentage
Column percentages are calculated based on each column's total.
| Gender | Prefer online shopping | Do not prefer |
|---|---|---|
| Men | 60% | 40% |
| Women | 40% | 60% |
In this example each column total is also 100, so the numbers come out the same. But the meaning is different: among people who prefer online shopping, 60% are men and 40% are women.
Column percentages are generally used to check the composition of the people who chose a particular response.
Total percentage
Total percentages are calculated based on the whole sample. For example, if 60 of all 200 people are men who prefer online shopping, the total percentage is 30%. Which percentage is more appropriate depends on the analysis question.
To compare differences in preference by gender, it is usually easiest to look at the proportions within each gender group.
So when reporting crosstab results, you should clearly indicate which group the percentages were calculated on.
What is the chi-square test?
The chi-square test compares the observed frequencies by category with the frequencies expected under a statistical hypothesis.
When used with crosstab analysis, it mainly means the chi-squared test of independence. The chi-squared test of independence checks whether two categorical variables are independent of each other, that is, whether they are statistically related.
For example, if gender and shopping channel preference are independent, you would expect shopping channel preference rates not to differ systematically by gender. Conversely, if the two variables are related, the actually observed frequencies may differ from the frequencies expected under independence.
The chi-squared test of independence evaluates these differences statistically.
Hypotheses of the chi-square test
The following hypotheses are usually set.
Null hypothesis (H₀): The two categorical variables are independent.
Alternative hypothesis (H₁): The two categorical variables are not independent.
The chi-square test computes a test statistic based on the differences between observed and expected frequencies. The chi-square statistic is written as follows. χ² = Σ (O - E)² / E
Here O is the observed frequency and E is the expected frequency. The larger the differences between observed and expected frequencies, the larger the chi-square statistic generally becomes. Statistical significance, however, is judged with the p-value calculated from the chi-square statistic and the degrees of freedom.
How do observed and expected frequencies differ?
To understand the chi-square test, you need to know the difference between observed and expected frequencies.
The observed frequency is the count found in the actual data. The expected frequency is the count expected under the assumption that the two variables are independent.
Let's use the gender and online shopping preference example from earlier again.
Actual observed frequencies
| Gender | Prefer online | Do not prefer |
|---|---|---|
| Men | 60 | 40 |
| Women | 40 | 60 |
There are 100 men and 100 women in total. Also, 100 people prefer online shopping and 100 do not. If the two variables are independent, you would expect the share preferring online shopping to be the same in each gender, based on the overall distribution.
Expected frequencies are calculated as follows.
Expected frequency = (row total × column total) ÷ total sample size
So the expected frequency for men who prefer online shopping is (100 × 100) ÷ 200 = 50.
Calculating the expected frequency of every cell the same way gives the following.
Expected frequencies under independence
| Gender | Prefer online | Do not prefer |
|---|---|---|
| Men | 50 | 50 |
| Women | 50 | 50 |
The observed frequencies differed between 60 and 40, but in the expected frequencies every cell was 50. The chi-square test evaluates whether such differences can be explained by chance sampling variation.
Real-world example: are gender and online shopping preference related?
Let's look again at the case of surveying 200 customers about gender and whether they prefer online shopping.
The research question is as follows.
"Is there a statistically significant association between gender and online shopping preference?"
Crosstab results
| Gender | Prefer | Not prefer | Total |
|---|---|---|---|
| Men | 60 (60%) | 40 (40%) | 100 |
| Women | 40 (40%) | 60 (60%) | 100 |
| Total | 100 | 100 | 200 |
Values in parentheses are row percentages calculated within each gender group.
Chi-square test results
| Indicator | Result |
|---|---|
| Sample size (N) | 200 |
| Pearson chi-square (χ²) | 8.00 |
| Degrees of freedom (df) | 1 |
| p-value | 0.0047 |
| Phi coefficient (φ) | 0.20 |
No continuity correction was applied.
How do you interpret the results?
While 60% of male respondents preferred online shopping, 40% of female respondents did. The two groups differed by 20 percentage points. The chi-square test gave χ²(1) = 8.00, p = .0047.
Because the p-value is smaller than the usual significance level of 0.05, you can reject the null hypothesis that gender and online shopping preference are independent. So you can interpret that there is a statistically significant association between gender and online shopping preference.
However, a statistically significant association does not let you conclude that gender directly causes shopping channel preference.
That is because other factors, such as age, occupation and purchase experience, may also be involved.
How do you interpret the p-value of a chi-square test?
In a chi-square test, the p-value is the probability, under the null hypothesis that the two variables are independent, of getting a chi-square statistic as large as the one actually observed or more extreme.
If the significance level is set at the usual 0.05, decisions are made as follows.
| p-value | Usual decision |
|---|---|
| p < .05 | Reject the null hypothesis; statistically significant association |
| p ≥ .05 | Not enough evidence to reject the null hypothesis |
For example, p = .003 means that, assuming the two variables are independent, the probability of a difference at least as large as the one observed is about 0.3%. But a small p-value does not mean the relationship between the two variables is strong. With a very large sample, even a small association can be statistically significant.
Conversely, with a small sample, even a relatively large difference in proportions may not be statistically significant. So in a chi-square test it is important to look not only at the p-value but also at the proportions in the actual contingency table and the effect size.
What are the phi coefficient and Cramér's V?
In a chi-square test, it matters not only whether the result is statistically significant but also how strong the association between the two variables is.
For this you can use effect size measures such as the phi coefficient and Cramér's V.
Phi coefficient
The phi coefficient is an association measure used mainly for 2×2 contingency tables, where each variable has two categories. In the earlier gender and online shopping preference example, the phi coefficient was 0.20. This indicates how strong the association between the two variables is.
However, when interpreting the size of the value, consider the research field and the purpose of the analysis.
Cramér's V
Cramér's V is an effect size measure that can be used not only for 2×2 tables but also for tables with more categories. For example, dividing age into 20s, 30s, 40s and 50s and preferred brand into A, B and C produces a 4×3 contingency table.
Here too, you can use Cramér's V to check the size of the association between the two variables.
| Indicator | Main use | Range of values |
|---|---|---|
| Phi coefficient | Mainly 2×2 tables | −1 to 1 under the signed definition for 2×2 tables |
| Cramér's V | Tables of various sizes | 0~1 |
A Cramér's V close to 0 indicates a weak association, and values closer to 1 indicate a stronger association. However, interpretation criteria can vary with the number of categories in the two variables, the sample size and the research context, so it is best to avoid applying a one-size-fits-all standard.
If the chi-square test is significant, in which categories did the differences arise?
The chi-square test checks whether there is an overall association between two variables.
But in a table with many categories, it can be hard to see which specific cells had more or fewer responses than expected. For example, suppose you compared four age groups and three brands.
Even if the chi-square test is significant, it does not tell you directly which age group chose which brand relatively often. In such cases you can check the standardized residuals or adjusted standardized residuals.
What is residual analysis?
A residual is the difference between the actually observed frequency and the expected frequency.
- Positive residual: the observed frequency is larger than expected
- Negative residual: the observed frequency is smaller than expected
- Residual near 0: observed and expected frequencies are similar
Standardized or adjusted standardized residuals let you compare how large the difference is in each cell. However, if you examine many cells at once, consider the multiple comparisons problem, and do not interpret a large residual as evidence of a causal relationship.
What kinds of chi-square tests are there?
There are several types of chi-square tests.
The main ones are the goodness-of-fit test, the test of independence and the test of homogeneity.
| Test | Purpose | Example use |
|---|---|---|
| Chi-square goodness-of-fit test | Tests whether the observed distribution across categories matches a specified expected distribution | Are the selection rates for each product color equal? |
| Chi-square test of independence | Tests whether two categorical variables are associated | Are gender and brand preference related? |
| Chi-square test of homogeneity | Tests whether the categorical distributions of different populations or groups are the same | Are product preference rates the same across regions? |
Chi-square goodness-of-fit test
Checks whether the observed distribution of one categorical variable matches a distribution set in advance. For example, you can test whether four product colors are chosen in equal proportions.
Chi-square test of independence
Checks whether two categorical variables are independent. It is used to analyze the relationship between two variables, such as gender and brand preference, or age group and service use.
Chi-square test of homogeneity
Compares whether the categorical response distributions of different groups are the same. For example, you can check whether the brand preference distributions of customers sampled separately in New York, Chicago and Houston are the same. The test of independence and the test of homogeneity use similar calculations on a contingency table, but they differ in the research question and the sampling design.
The chi-square test examined in this article alongside crosstab analysis is mainly the test of independence.
Assumptions to check before a chi-square test
The chi-square test is useful for analyzing categorical data, but it must be used under appropriate conditions.
Check that the data are frequency data.
The chi-square test of independence generally uses observed frequencies for each combination of categories. It is not appropriate to enter means or percentages as if they were frequencies. Check that the analysis data represent frequencies of actual observations.
Check that observations are independent.
In the usual chi-square test of independence, observations must be independent of each other. For example, treating the same person's responses before and after using a service as two independent observations can cause problems. To compare the same subjects' before-and-after binary responses, McNemar's test or similar may be more appropriate.
Check that expected frequencies are not too small.
Depending on sample size and expected frequencies, the approximation using the chi-square distribution can become inaccurate. The traditional rule of checking whether expected frequencies are 5 or more is often used, but actual adequacy depends on the size of the table and the share of small expected frequencies.
So you should not judge solely by the simple rule that every cell's expected frequency must be 5 or more. When expected frequencies are small, you can consider Fisher's exact test or other exact or simulation-based methods.
Check that the categories are defined appropriately.
For example, dividing age groups too finely can leave very few observations in each cell. Conversely, forcibly merging categories with different meanings can make important differences disappear. So the criteria for dividing categories should be decided based on the research purpose and the characteristics of the data.
Check for missing values.
If survey responses are missing, the sample size used in the crosstab analysis can change. Before the analysis, decide whether to exclude missing values or treat them as a separate category. However, treating missing values as a response category is not always appropriate. Consider why the data are missing and the research purpose.
How do the chi-square test and correlation analysis differ?
The chi-square test and correlation analysis both look at relationships between variables, but they differ in the data they mainly use and the meaning of their results.
| Aspect | Crosstab · chi-square test | Correlation analysis |
|---|---|---|
| Main purpose | Check association between categorical variables | Analyze the direction and strength of a relationship between two variables |
| Typical data | Gender, occupation, purchase (yes/no), preferred brand | Study time, test scores, income, satisfaction rank |
| Main indicators | χ², p-value, Cramér's V | Pearson r, Spearman ρ, etc. |
| Direction of relationship | The usual χ² statistic does not indicate direction | The sign of the correlation coefficient can show direction |
| Main result | Distribution by category and test of independence | Direction and strength of the relationship |
For example, to analyze the relationship between gender and brand preference, you could consider crosstab analysis and the chi-square test. To check the linear relationship between study time and test scores, on the other hand, you could consider Pearson correlation analysis.
Of course, there are also association measures for categorical variables that can carry a sign, such as the phi coefficient, and other association methods may be used depending on the measurement level of the data. So when choosing an analysis, consider both the measurement level of the variables and the research question.
How do you report crosstab and chi-square test results?
In a research paper or analysis report, it is good to report not only the frequencies and percentages in the contingency table but also the chi-square statistic, degrees of freedom, p-value and effect size.
Using the earlier gender and online shopping preference example, you could write it as follows.
Example of reporting results
Crosstab analysis and a Pearson chi-square test of independence were conducted to examine the association between gender and online shopping preference. In the crosstab analysis, the rate of preferring online shopping was 60.0% for men and 40.0% for women. The chi-square test showed a statistically significant association between the two variables, χ²(1, N = 200) = 8.00, p = .005, φ = .20.
Reporting results this way lets readers see not only the response distribution in each group but also whether there is a statistically significant association and how strong it is. In real research, it is also good to state, as needed, the sample size in each group, the basis for calculating percentages and how missing values were handled.
Where can crosstab analysis and the chi-square test be used?
Crosstab analysis and the chi-square test are used in many fields that want to check relationships between categorical variables.
Marketing and management
You can analyze brand preference by age group, purchase experience by gender, service use by customer type and more.
Surveys and social science research
You can look at differences in the distribution of attitudes or choices by respondent characteristics such as gender, occupation and education level.
Education research
You can analyze preferred learning styles by grade, participation in and completion of educational programs, learning types by student characteristics and more.
Health and medical research
You can compare the association between lifestyle habits and particular health conditions, whether symptoms occur by group, categorical outcomes by treatment group and more.
HR and organizational research
You can analyze turnover intentions by department, training participation by job level, and the relationship between work arrangements and preferences for benefit programs.
Market research
You can check differences in product choice, ad awareness, purchase experience and brand preference across consumer groups. It is a basic analysis method especially for checking whether response rates in a survey differ by respondent characteristics.
Crosstab analysis shows differences, and the chi-square test judges association.
Crosstab analysis compares response distributions between groups by checking the frequencies and proportions for each combination of two categorical variables.
The chi-square test of independence decides whether there is a statistically significant association between such categorical variables. Using the two methods together lets you see not only which responses appeared most in which group, but also how statistically distinct the observed differences in distribution are.
However, a significant chi-square test does not prove a causal relationship between the two variables. It is also important to look not only at the p-value but also at the actual frequencies and percentages and effect sizes such as the phi coefficient or Cramér's V.
The purpose of crosstab analysis and the chi-square test is not simply to compare response counts by group, but to understand statistically the differences and associations that appear in categorical data.