In previous articles, we introduced t-tests, analysis of variance (ANOVA) and other methods for comparing means between groups. Today's article, this article mainly introduces what is the Chi-square test and how the Chi-square test is used for comparison between groups.
What is a chi-square test?
According to Wikipedia, the Chi-Squared Test is often used to compare rates or proportions between groups. It is a statistical quantity that approximately obeys the Chi-square distribution when the null hypothesis is established. of Hypothesis test . In the absence of other qualifications or instructions, the chi-square test generally refers to Pearson's Chi-square Test .
Before using the chi-square test, there are two points to note:
1. Chi-square test is only applicable to variables whose outcome is binary or unordered multi-category; if the outcome is hierarchical data, the Chi-square test is usually not used, but the rank sum test. We will use the detailed method in the next series. The article will introduce again.
2. In addition to the comparison of rates or proportions, the chi-square test is often used for goodness-of-fit test to compare the difference between the actual value and the theoretical value (or predicted value). Therefore, it is often used to test whether a sample satisfies a certain distribution, a certain Whether the prediction effect of the model is good or not, etc.
Five scenarios commonly used in chi-square verification
When will the Chi-square test be used, here are six common situations:
- Comparison of the rates of two or more groups , That is, the outcome is a binary variable (such as death and survival, negative and positive, etc.). In this case, the chi-square test can be used directly.
- Comparison of the proportions of two or more groups , Usually the outcome is disordered multi-category variables (Such as the subtype of the disease, etc.), in this case, you can also use the chi-square test directly. However, if The number of samples is too small (generally considered to be less than 40 even if it is too small) , Usually the comparison of rates or proportions between groups is not directly used for the chi-square test, but It is recommended to use Fisher for exact verification .
- Comparison of multiple group rates or proportions . If there is a statistical difference and you want to make further pairwise comparisons, the Bonferroni method is often used to correct the verification level. For example, the three groups of A, B, and C are compared in pairs, and a total of 3 comparisons are required. Chi-square test can be performed on A and B, A and C, B and C, but the test level is not 0.05, but 0.05/3 =0.0167, that is, three comparisons are considered statistically different with P<0.0167.
- Comparison of multiple group rates , If the grouping variables have a hierarchical order, you can also consider Trend Chi-Square Test , Whether the observation rate increases with the increase of the group level.
- if Paired design , Need to consider Paired chi-square test , The result conclusion at this time is different from the ordinary Chi-square test.
Chi-square test: Comparison of the rates of the two groups
We will use the OSAS data shown in Figure 1 to explain. In the data in Figure 1, it is planned to compare whether there is a difference in the incidence of OSAS between obese people and normal people. Both the grouping index and the outcome index are categorical variables, so the chi-square test is used.

Figure 1 OSAS data
Select the JMP menu "Analyze → Fit Y with X" (Figure 2) to enter the interface for comparison between groups. In this example, obesity is grouping and OSAS is the result, so put "Obesity" into "X, factor" and "OSAS" into "Y, response" in the dialog box (Figure 3).

Figure 2 Chi-square verification operation-function table selection

Figure 3 Chi-square verification operation-variable selection
The result automatically output by JMP software includes three parts: mosaic map, contingency table and chi-square test result.
Let us interpret these results one by one.
1. Mosaic
The first part is the mosaic map (Figure 4), which visually shows the proportion of each group of people through graphics. The total length of the horizontal and vertical coordinates represents 100%. In Figure 4, the horizontal axis represents obesity, and the vertical axis represents whether OSAS has occurred. In the legend on the right, it can be seen that the red represents the occurrence of OSAS, and the blue represents the absence of OSAS (normal).
It can be seen from the abscissa of the figure that the number of people in the normal weight group is more, about twice that of the obese group.
It can be seen from the ordinate that the proportion of obese people who have OSAS is higher (the red area in the obese group is higher than that in the normal group), but whether the difference is statistically significant, it is necessary to refer to the results of the chi-square test to judge.

Figure 4 Chi-square test result-mosaic
2. Contingency table
The second part is the contingency table. Each grid in the contingency table has 4 rows of data. The header at the top left of the table gives the meaning of these 4 rows of data. They are count, total percentage, column percentage, and row percentage.

Figure 5 Chi-square test results-contingency table
3. Chi-square test statistical analysis results
The third part is the statistical analysis result of the chi-square test. The results include three parts of likelihood ratio chi-square, Pearson chi-square and Fisher exact test (Figure 6). In practice, the Pearson chi-square test result is usually used, but if the number of cases is less than 40 or the theoretical frequency is less than 5 or even less than 1, it is generally recommended to choose Fisher's exact test result.

Figure 6 Chi-square test results-Chi-square test statistical analysis results
There are many samples in this example, and Pearson chi-square is generally used. Of course, for the sake of rigor, we still look at the theoretical frequency situation. Click the red triangle button next to the contingency table and select the desired value in the drop-down menu (Figure 7) to get the theoretical frequency of each grid, that is, the position shown by the arrow in Figure 8.

Figure 7 Chi-square verification operation-output theoretical frequency

Figure 8 Chi-square verification results-theoretical frequency results
It can be seen that the theoretical frequency of all grids is greater than 5, so choose the Pearson chi-square result. The results show that there is a statistical difference in the incidence of OSAS between obesity and normal people (Pearson=5.970, P=0.0146) (Figure 6).

Figure 9 Chi-square test results-Chi-square test statistical analysis results
Chi-square test: Comparison of multiple group rates
We will continue to explain based on the OSAS data shown in Figure 1. In the data in Figure 1, we plan to compare whether there is a difference in the incidence of OSAS in patients with different tonsil sizes.
In this case, the outcome index is OSAS, which is a two-category variable; the grouping index is tonsil size, which is divided into three categories: <2, =2, and >2, which is a multi-category variable. First, perform the chi-square test, the operation is the same as above, and the result is shown in Figure 10 below.

Figure 10 Chi-square test results
The contingency table in Figure 10 shows that the number of study cases is greater than 40 and the theoretical frequency (expected value) of all grids is greater than 5. Therefore, the Pearson result is selected. The difference in the incidence of OSAS in patients with different tonsil sizes is statistically significant (Pearson=6.305 , P=0.0428).
The above results only show that there are statistical differences in the incidence of OSAS between the three groups, but the specific differences between the two groups need to be further compared between the two groups.
For classified data, the JMP program cannot directly give the pairwise comparison results, and the Bonferroni method needs to be used to calibrate the verification level. Then the chi-square test is performed on any two groups of them and compared with the corrected test level. In this example, a total of 3 pairwise comparisons are performed, and the calibration level after calibration is:

In other words, when comparing the two pairs, the difference is considered statistically significant when the P value is less than 0.0167. The result of the pairwise comparison is shown in Figure 11. The results showed that the P value of less than 2 vs greater than 2 was less than 0.0167, which was statistically significant, and the other groups were not statistically significant.

Figure 11 Pairwise comparison results
In summary, statistical analysis shows that there is a statistically significant difference in the incidence of OSAS between obese people and normal people. There is a statistically significant difference in the incidence of OSAS between people with tonsil sizes less than 2 and greater than 2, and there is no statistically significant difference between the remaining groups.
Chi-square test: Comparison of the proportions of two or more groups
The comparison of the two/multi-group ratios, the idea and the JMP software implementation process are completely consistent with the comparison of the two/multi-group ratios. It's just that the explanation is different. If the proportions between the groups are statistically different, it means that the distributions between the groups are different. Similarly, if there is a statistical difference in the ratio of multiple groups, you can also perform a pairwise comparison. The idea is the same as the pairwise comparison of multiple group rates.
The above is today's sharing. In the next article in this series, we will introduce the extension of the chi-square test—rank data rank sum test, trend chi-square and paired chi-square test. If you want to know more about the in-depth application of JMP, welcome Join JMP LINE official account , Get practical JMP operation skills and online course information regularly!

original: Dry Goods | Chi-Square Test-An Artifact for Comparison between Classification Data Groups
Statistical method analysis article recommendation:
Thoughts and Analytical Methods of Rank Sum Test and Pairwise Comparison
There are 3 commonly used t-tests in one literature-independent-sample t-test, single-sample t-test and paired t-test
Perform normal state test and homogeneity test of variance in JMP
Analysis of Variation (ANOVA) and Pairwise Comparison: Thoughts and Analytical Methods