In the last article, we learned about the basic Chi-square test. As for the article to be introduced today, it is an extension of Pearson's chi-square. This article mainly introduces three scenarios:
- Used for comparison between graded data sets Rank sum test
- Used to observe trend changes Trend Chi-Square Test
- For pairing data Paired chi-square test
Rank sum test for "comparison of two or more sets of grade data"
As mentioned in the previous article, if the outcome is ordered categorical data (grade data), in order to compare whether there are statistical differences between two or more groups of graded data, the chi-square test is generally not used at this time, because the chi-square test cannot show Rank order, but use rank sum test.
Regarding the rank sum test, mainly Comparison of groups or groups of skewed distribution data, not graded data . Although they are all rank sum tests, because of the different formats of continuous data and grade data, the operations on JMP are also different, so this article focuses on the introduction Grade information The operation of rank sum test.
Example 1: In the data in Figure 1, I want to compare whether there is a difference in the size of tonsils between obese and non-obese patients. The grouping index of the data is a two-category variable, and the outcome index is a graded 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 reflect 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 index tonsil size needs to be defined as a continuous type, as shown in Figure 2.

Figure 2 Data types of outcome indicators
Select the menu "Analysis" → "Fit Y with X" in the JMP menu. In the pop-up dialog box, put "Fatness" in "X, Factor", and "Tonsil Size" in "Y, Response".
In the result, click the red triangle button next to the single factor analysis of "obesity-tonsil size", and select "nonparametric → Wilcoxon test "(image 3).

Figure 3 Operation of rank sum verification-function table selection
The results are shown in Figure 4. The difference in tonsil size between obese and non-obese patients was not statistically significant (Z= -0.0478, P=0.9619).

Figure 4 Results of rank sum test
Please note: If the input software is not in the form of the original data as shown in Figure 1, but in the form of a contingency table, in this case, usually the first column is the grouping variable, the second column is the ending variable, and the third column is the frequency. That is, the number of examples of the combination of the first two columns, and 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 X to Y" interface, you need to drag the frequency series to "Frequency".
Trend Chi-Square Test
Trend chi-square test is mainly used for grouping into a certain order of multi-category variables (such as multiple age groups, disease severity), the outcome variable is a two-category rate variable, and its purpose is to observe whether the positive rate of the outcome variable varies The grouping order increases or decreases.
Example 2: In the previous article, we compared the incidence of OSAS in patients with different tonsil sizes based on the data in Figure 1. The results are shown in Figure 5. There is a statistically significant difference in the incidence of OSAS in patients with different tonsil sizes (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 index is the size of the tonsils, which are divided into three categories of <2, =2 and >2, which belong to multi-class data and are graded data.
Please note: In this case, if you find that there are statistical differences between the groups, you can continue to consider at least two things in the future:
- Consider whether you need to make a pairwise comparison to see which two groups are different. This content has been explained in detail in the previous article;
- Consider whether the positive rate has a tendency to change with the order of the group (such as the gradual increase in tonsils), that is, the trend chi-square test is performed, because the grouping is ordered and multi-classified, and the outcome is the rate indicator.
Click the red triangle button next to the "tonsilla size-OSAS" contingency analysis, and select "Cochran-Armitage Trend Test" from the drop-down menu (Figure 6). The results are shown in Figure 7.

Figure 6 Trend verification operation-function table selection
In the results of the Cochran-Armitage trend test:
When the statistic (Z) ≤ 0, the one-sided P value (probability> Z) gives the P value in the first column of the contingency table (Figure 5). If the P value is less than 0.05, it indicates the incidence of the first column of outcome indicators. Showing a downward trend;
When the statistic (Z)>0, the one-sided P value gives the P value in the second column of the contingency table (Figure 5). If the P value is less than 0.05, it indicates that the incidence of the second column of outcome indicators is on a downward trend. In other words, the first column is on the rise.
In this case, the Z value is greater than 0, indicating that the first column (OSAS incidence) is on the rise (see the row percentage in the contingency table for the incidence of OSAS in each group), that is, the incidence of OSAS increases with the increase in the size of the tonsils. This trend is statistically significant (Z=2.4871, P=0.0064) (Figure 7).

Figure 7 Trend verification results
Please note: The difference between this example and example 1 is that the outcome index of example 1 is grade data, so the rank sum test is performed to compare the difference in grade between different groups;
In this case, the grouping index is grade data, and the outcome is a binary variable. Therefore, the chi-square test can be used for comparison between groups. If you want further analysis, you can perform a trend test to explore the incidence of outcome indicators as the grouping level changes. Trend of change.
Paired chi-square test
Paired chi-square test is a chi-square test for paired data. Common pairing designs are comparisons of two detection methods in the same population, comparisons before and after treatment in the same population, and so on. The data of this design cannot use the ordinary Pearson chi-square test, but must use the paired chi-square test.
Example 3: A tumor hospital used MRI and CT to diagnose liver cancer in the same patient. A total of 119 patients were enrolled, 49 cases of liver cancer were found in CT diagnosis, and 43 cases of liver cancer were found in MRI diagnosis. The data is shown in Figure 8. I want to compare whether there is a difference in the positive rate of the two diagnostic methods.

Figure 8 Diagnostic data of liver cancer
The purpose of this study is to compare whether the diagnosis results of the two methods are different, which belongs to the category of difference test. But unlike the previous case, this case does not have a grouping index, but compares two results of the same population. This is a common design type in medical diagnostic tests, that is, self-matching design. The same research population receives two different treatments. The two outcome indicators are both binary categorical variables. For the paired design of categorical variables, the paired chi-square test is generally used for statistical analysis.
When JMP performs a paired chi-square test, the data needs to be organized into a specific format. Note that the format of the data preparation should be as shown in (Figure 8), otherwise the analysis of the paired test cannot be completed.
In JMP, select the menu "Analyze" → "Fit X to Y" to enter the dialog box of difference analysis. In this example, the CT diagnosis result and the MRI diagnosis result are two results of the same population, so you can put any variable Enter "Y, response", the other "X, factor", and "number of samples" into "frequency" (Figure 9).

Figure 9 Consistency verification of paired data-variable selection
The output result of JMP software is shown in Figure 10. It can be seen from the contingency table that the positive rate of CT diagnosis is 41.18%, and the positive rate of NMR diagnosis is 36.13%. The result also shows the Pearson chi-square test result. However, it must be noted that the chi-square test result given in the result is not what we want. The Pearson chi-square test is for independent samples, and the result of the paired chi-square test requires one step.

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

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

Figure 12 Consistency verification of paired data-result output
As shown in Figure 12, there are two parts of the output: Kappa consistency check sum difference test.
- The Kappa coefficient gives the result of the consistency test, 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 rate of the two diagnostic methods for the same group of people.
The purpose of this example is to compare the differences between the two methods. Therefore, the results of the second part of McNemar test were selected. The results showed that the diagnostic positive rates of the two methods were not statistically different (chi-square=1.50, P=0.2207). In the absence of a gold standard, the results can only show whether the positive rates of the two methods are statistically different, and cannot explain the pros and cons of the diagnostic methods.
Summary: Select the results according to the purpose of the research
Finally, it needs to be emphasized: in the pairing design, if the outcome is a categorical variable, determine which outcome to choose according to the purpose of your research. If the purpose of the research is to compare the differences, as in this example, you need to choose the Bowker / McNemar test (2*2 four grid table gives McNemar test, 3*3 and above symmetric contingency table gives Bowker test) instead of Pearson chi-square test; if the research purpose is to check whether there is a correlation, you can use the Pearson chi-square test and output the corresponding correlation index; if the research purpose is to observe consistency, you can choose the Kappa consistency test.
Comparing the McNemar test result in Figure 12 with the Pearson chi-square test result in Figure 10, it can be found that the two are completely different. Therefore, When performing a paired chi-square test, you must pay attention to the choice of statistical results. Choosing the wrong statistical method will lead to wrong conclusions.
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: The extension of the chi-square test-rank data rank sum test, trend chi-square and paired chi-square
Recommended reading:
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