In the previous article, we learned about the basic chi-square test. Today's article is an extension of Pearson chi-square. This article mainly introduces three scenarios:
- Rank sum test for comparison between groups of ranked data
- Chi-square test for trend to observe trend changes
- Paired Chi-Square Test for Paired Data
Rank sum test for comparing two or more groups of ranked data
As mentioned in the previous article, if the outcome is ordered categorical data (ranked data), in order to compare whether there are statistical differences between two or more groups of rank data, the chi-square test is generally not used because the chi-square test cannot show the rank order. Instead, the rank sum test is used.
The rank sum test is mainly about comparing groups or multiple groups of skewed distribution data, not rank data . Although they are all rank sum tests, the operations on JMP are different due to the different formats of continuous data and rank data. Therefore, this article focuses on introducing the rank sum test operation of rank data .
Example 1: In the data in Figure 1, we want to compare whether there is a difference in tonsil size between obese and non-obese patients. The grouping indicator of the data is a binary variable, and the outcome indicator is a level data.
At this time, if the chi-square test is used, it can only indicate whether there is a statistical difference in the composition ratio between the groups. If you want to show whether there is a difference in degree or level between the groups, you need to use the rank sum test for analysis.

Figure 1 OSAS data
It should be noted that when setting the data format, the outcome indicator tonsil size needs to be defined as continuous, as shown in Figure 2.

Figure 2 Data types for outcome indicators
In JMP, select the menu "Analyze" → "Fit Y by X". In the dialog box that pops up, put "Obesity" in "X, Factor" and "Tonsil Size" in "Y, Response".
In the results, click the red triangle button next to the "Obesity-Tonsil Size" one-way analysis and select "Nonparametric → Wilcoxon Test " in the drop-down menu (Figure 3).

Figure 3 Rank Sum Test Operation - Function Table Selection
The results are shown in Figure 4 . There was no statistically significant difference in tonsil size between obese and non-obese patients (Z = -0.0478, P = 0.9619).

Figure 4 Rank Sum Test Results
Please note: If the input to the software is not in the original data format as in Figure 1, but in the form of a contingency table, in this case, the first column is usually the grouping variable, the second column is the outcome variable, and the third column is the frequency, that is, the number of cases in the combination of the first two columns. The data format is shown in Figure 8 later in this article. In this case, the statistical analysis operation of the difference test is shown in Figure 9. In the "Fit Y by X" interface, you need to drag the frequency column to "Frequency".
Chi-square test for trend
The trend chi-square test is mainly used for multi-classification variables that are grouped in a certain order (such as multiple age groups, disease severity), and the outcome variable is a binary rate variable. Its purpose is to observe whether the positive rate of the outcome variable has a trend of increasing or decreasing with the grouping order.
Example 2: In the previous article, we compared whether there was a difference in the incidence of OSAS among patients with different tonsil sizes based on the data in Figure 1. The results are shown in Figure 5, and the difference in the incidence of OSAS among patients with different tonsil sizes was statistically significant (Pearson=6.305, P=0.0428).

Figure 5 Comparison of the incidence of OSAS in patients with different tonsil sizes - statistical results
In this example, the grouping indicator is tonsil size, which is divided into three categories: <2, =2, and >2. It is multi-classification data and is hierarchical data.
Please note: In this case, if you find a statistical difference between the groups, you can at least consider doing two things:
- Consider whether it is necessary to make pairwise comparisons to see which two groups have differences. This has been explained in detail in the previous article.
- Consider whether the positive rate has a trend that changes with the order of groups (such as the gradual enlargement of tonsils), that is, to conduct a trend chi-square test, because the grouping is ordered multi-classification and the outcome is a rate indicator.
Click the red triangle button next to the "tonsil size-OSAS" contingency analysis and select "Cochran-Armitage trend test" in the drop-down menu (Figure 6). The results are shown in Figure 7.

Figure 6 Trend verification operation - function table selection
Cochran-Armitage trend test results:
When the statistic (Z) is ≤ 0, the one-sided P value (probability > Z) gives the P value of the first column of the contingency table ( Figure 5 ), and a P value less than 0.05 indicates that the incidence of the outcome indicator in the first column is on a downward trend;
When the statistic (Z) > 0, the one-sided P value gives the P value of the second column of the contingency table (Figure 5). A P value less than 0.05 indicates that the incidence of the outcome indicator in the second column is on a downward trend, that is, the first column is on an upward trend.
In this case, the Z value was greater than 0, indicating that the first column (the incidence of OSAS) showed an upward trend (the incidence of OSAS in each group can be found in the row percentages in the contingency table), that is, the incidence of OSAS increased with the increase of tonsil size, and this trend was statistically significant (Z = 2.4871, P = 0.0064) ( Figure 7 ).

Figure 7 Trend test results
Please note: The difference between this example and Example 1 is that the outcome indicator in Example 1 is graded data, so a rank sum test is performed to compare the differences in grades between different groups;
In this case, the grouping indicator is ordinal data and the outcome is a binary variable, so the chi-square test can be used for inter-group comparison. If further analysis is required, a trend test can be performed to explore the trend of the incidence of the outcome indicator as the grouping level changes.
Paired Chi-Square Test
The paired chi-square test is a chi-square test for paired data. Common paired designs include comparisons of two testing methods for the same population, comparisons of the same population before and after treatment, etc. The data of this design cannot be tested with the ordinary Pearson chi-square test, but with the paired chi-square test.
Example 3: A cancer hospital used MRI and CT to diagnose liver cancer in the same patient. A total of 119 patients were included, 49 cases of liver cancer were found by CT, and 43 cases of liver cancer were found by MRI. The data are shown in Figure 8. It is desired to compare whether there is a difference in the positive diagnostic rate between the two diagnostic methods.

Figure 8 Liver cancer diagnosis data
The purpose of this study is to compare whether there is a difference in the diagnostic results of the two methods, which falls into the category of difference test. However, unlike the previous case, this case does not have a grouping indicator, but a comparison of two results of the same population. This is a common design type in medical diagnostic tests, that is, a self-paired design, in which the same research population receives two different treatments. Both result indicators are binary variables. For paired designs of categorical variables, paired chi-square tests are generally used for statistical analysis.
When JMP performs paired chi-square test, the data needs to be organized into a specific format. Please note that the data preparation format should be as shown in (Figure 8), otherwise the paired test analysis cannot be completed.
In JMP, select the menu "Analysis" → "Fit Y by X" to enter the dialog box of differential analysis. In this example, the CT diagnosis results and the MRI diagnosis results are two results of the same population, so any variable can be put into "Y, response" and the other into "X, factor", and "sample number" into "frequency" (Figure 9).

Figure 9. Consistency test of paired data - variable selection
The output results of JMP software are shown in Figure 10. From the contingency table, we can see that the positive rate of CT diagnosis is 41.18%, and the positive rate of MRI diagnosis is 36.13%. The results also give the Pearson chi-square test results. However, it must be noted that the chi-square test results given in the results are not the results we want. The Pearson chi-square test is for independent samples, and the paired chi-square results need to be operated one step further.

Figure 10 JMP output results
In the result interface, click the red triangle button next to the "MRI diagnosis results-CT diagnosis results" contingency analysis, and select "Consistency Statistics" in the drop-down menu (Figure 11):

Figure 11: Consistency test of paired data - function table selection
The output result is shown in Figure 12 below:

Figure 12: Consistency test of paired data - result output
As shown in Figure 12, two parts of results are output: Kappa consistency check sum and difference test.
- The Kappa coefficient gives the consistency test result, indicating whether the two diagnostic methods are related or consistent.
- The Bowker/McNemar test result is a difference test result of paired data, indicating whether there is a statistical difference in the positive detection rate of the two diagnostic methods for the same group of people.
The purpose of this case is to compare the differences between the two methods, so the results of the second part of the McNemar test were selected. The results showed that there was no statistical difference in the positive diagnostic rate of the two methods (chi-square = 1.50, P = 0.2207). In the absence of a gold standard, the results can only indicate whether there is a statistical difference in the positive rate of the two methods, and cannot explain the advantages and disadvantages of the diagnostic methods.
Summary: Select results based on research purpose
Finally, it should be emphasized that in a paired design, if the outcome is a categorical variable, you should determine which outcome to choose based on your research purpose. If the purpose of the study is to compare differences, as in this example, you need to choose the Bowker/McNemar test (a 2*2 four-cell table gives the McNemar test, and a 3*3 or higher symmetrical contingency table gives the Bowker test) instead of the Pearson chi-square test; if the purpose of the study is to test whether there is an association, you can use the Pearson chi-square test and output the corresponding association index at the same time; if the purpose of the study is to observe consistency, you can choose the Kappa consistency test.
Comparing the McNemar test results in Figure 12 with the Pearson chi-square test results in Figure 10, we can find that the two are completely different. Therefore, when conducting paired chi-square tests, we must pay attention to the selection of statistical results. Choosing the wrong statistical method will lead to wrong conclusions.
If you want to know more about JMP applications, please join the JMP LINE official account to get practical JMP operation skills and online course information regularly!

Original article: Extension of Chi-square Test - Rank Sum Test for Rank Data, Trend Chi-square and Paired Chi-square
Recommended reading:
Thinking context and analysis methods of rank sum test and pairwise comparison
Learn 3 common t-tests - independent sample t-test, single sample t-test and paired t-test
Performing Normality and Variance Homogeneity Tests in JMP
Thinking context and analysis methods of analysis of variance (ANOVA) and pairwise comparison