The most comprehensive chi-square test summary on the entire network

This article organizes all the contents of the chi-square test, includingthe definition of the chi-square test (basic idea, calculation of chi-square value, analysis of applicable conditions ), Chi-square test classification (2*2 four-grid table chi-square, R*C table chi-square, paired chi-square, chi-square fitting excellence degree test, stratified chi-square), How to analyze the chi-square test (data format, software operation, result interpretation, chi-square multiple comparisons), a> (parametric test and non-parametric test, other methods of difference analysis, etc.) 5 most of the content. Comparative analysis (multiple-choice question analysis, logistic regression analysis to screen variables, visual analysis of categorical data relationships, trend chi-square judgment whether there is Linear trend), Applications of chi-square test in other aspects

  1. Chi-square test definition
  2. Basic idea
    Chi-square test, also known as independence test, is a hypothesis testing method invented by mathematician Carl Pearson to test whether two variables are related. The basic idea is to count the degree of agreement between the actual frequency and the theoretical frequency of the sample. It is mainly used in the analysis of the relationship between classified data and classified data. That is what we often call the study of the difference between classified data and classified data. For example, study the differences in whether boys and girls smoke. The basic idea of ​​the chi-square test can also be understood through the basic formula of the chi-square value.
  3. Chi-square value calculation
    (1) Chi-square value calculation formula
    Chi-square value basic formula - Pearson

(\chi^2=\sum\frac{(O-E)^2}E(\chi^2\geq0))
where O is the actual frequency and E is Theoretical frequency, chi-square value representsthe degree of deviation betweenthe actual frequency and the theoretical frequency. The larger the chi-square value, the greater the deviation between the actual frequency and the theoretical frequency.
At the same time, the chi-square value is also affected by the degree of freedom . The greater the degree of freedom v, the greater the chi-square value. will be larger, so only by considering the influence of the degree of freedom v, the chi-square value can correctly reflect the deviation between the actual frequency and the theoretical frequency.
(2) Chi-square test degree of freedom
The degree of freedom of the chi-square test has nothing to do with the sample size n, but depends on the grid in the contingency table that can freely take values. Number, degree of freedom calculation formulav=(number of rows-1)*(number of columns-1). For example, there are two rows and two columns of data in a four-grid table, and the degree of freedom = (2-1)*(2-1)=1.
(3) Theoretical frequency calculation
The chi-square value calculation formula involves the calculation of the theoretical frequency. The calculation of the theoretical frequency of the chi-square test is based on the hypothesis test H0. Under the premise, calculate the theoretical frequency.
The specific calculation method is: for each cell, its theoretical frequency E=(row total × column total)/total number of samples n. That is, the theoretical frequency of the cell in row R and column C is (total of row R × total of column C)/total sample size n.

  1. Judgment of applicable conditions

Generally speaking, the chi-square test we call is Pearson chi-square, and the basic formula for chi-square value is also the Pearson chi-square value calculation formula. In addition, there are two chi-square values ​​- yates continuity corrected chi-square and Fisher's chi-square.

The selection of the three chi-square values ​​requires combining the number of variables, sample size n, theoretical frequency E distribution, etc., to select the chi-square value that should be used in the end. The specific selection criteria are as follows:

  • For a 2*2 four-cell table (R=2, C=2) n>=40, and all E>=5, use Pearson chi-square; n>=40, but 1<=E< appears in 1 of the cells. 5, use yates continuity correction chi-square; if E <1 or n<40 appears in any grid, use Fisher chi-square (only used in 2*2 tables).
  • For the R*C table (any one of R and C is greater than 2; and R>=2, and C>=2) all E>1 and the proportion of 1<=E<5 grids is less than 20%, use Pearson Chi-square , otherwise use yates continuity correction chi-square.

Yates continuity corrected chi-square formula:

  1. Chi-square test classification

The chi-square test can be divided into the following five categories from the perspective of frequency of use: independent sample 2*2 table chi-square test (four-cell table chi-square), multiple independent samples R*C table chi-square test, and chi-square fitting Goodness test, paired design data chi-square test, stratified chi-square test. Each will be explained next.

  1. Independent sample 2*2 table chi-square test
    The four-box table chi-square test is the most commonly used in daily research, and is used to compare whether there is a difference in the composition ratio of two samples. A four-cell table is a commonly used data table format. The table consists of four cells, each cell representing a different combination of a categorical variable. The four-grid representation is as follows. The rest of the data in the table can be calculated using the four data abcd, so it is also called the four-grid table data.


In addition to the basic formula mentioned above, the four-grid table chi-square test also has a unique formula for the four-grid table:

(\chi^2=\frac{(ad-bc)^2n}{(a+b)(c+d)(a+c)(b+d)})< a i=1>Note: n>=40, and all E>=5, use Pearson chi-square; n>=40, but 1<=E<5 appears in 1 grid Then use yates continuity correction chi-square; if E <1 or n <40 appears in any grid, use Fisher chi-square (only used in 2*2 tables).

  1. Multiple independent samples R*C table chi-square test

R row, C column (any one of R and C is greater than 2) table data chi-square test, used to analyze the difference between two certain categories of data, similar to the four-grid table chi-square test, but it is impossible to determine which two groups are specific There are differences between the data and multiple comparisons need to be made. The Bonferroni method is often used to make multiple comparisons between two groups. The SPSSAU chi-square test automatically outputs multiple comparison analysis results.

Data example:The following figure shows the results of the 3*2 table chi-square test:

Use the chi-square test to study the difference in the therapeutic effects of different therapies. As can be seen from the table above: the chi-square value is 21.038, and the p value is less than 0.05, indicating that the therapeutic effects of different therapies are significantly different. For specific differences between the two groups, please see the multiple comparison results below.

From the analysis of the above table, it can be seen that the external plaster group, physical therapy group, and drug treatment group were subjected to multiple comparisons between the two groups, and the treatment effects showed significant differences.

3. Chi-square goodness of fit

Chi-square goodness of fit is used to analyze whether the actual proportion of data is consistent with the expected proportion. It is only for categorical data, such as gender, occupation, education, etc. For example, if the male-to-female ratio of the samples collected is expected to be 6:4, is the expected ratio consistent with the actual male-to-female ratio of the samples collected? You can use the chi-square goodness-of-fit test analysis.

At the same time, the chi-square goodness-of-fit test is often used in the analysis of multiple-choice questions in questionnaires to analyze whether there is a difference in the proportion of selected multiple-choice question options. This will also be explained in detail later in the Chi-square test application section.

Data example:The following figure shows the results of the chi-square goodness-of-fit test:

Conduct a chi-square goodness-of-fit test for body shape to study whether the sample data distribution is consistent with the expected distribution. As can be seen from the table above: none of the body shapes are significant (chi-square value is 7.018, p>0.05), indicating The sample body size distribution is consistent with expected proportions.

4. Chi-square test of paired design data

The paired chi-square test is used to analyze the difference between two paired classification data. For example, two methods are used to diagnose the same batch of patients (the diagnostic results are positive & negative). To determine whether there is a difference in the diagnostic results of the two methods, you can use paired Chi-square test was performed for analysis.

Data example:The following figure shows the results of the paired chi-square test:

From the analysis of the above table, we can see that the paired chi-square test is used to analyze the difference in the diagnostic results of method A and method B. From the results of the paired chi-square analysis, it can be seen that p=0.022<0.05, indicating that the test results of the two methods A and B are Significant differences.

5. Stratified chi-square test

The stratified chi-square is based on the chi-square test and further considers the interference of stratified items (confounding factors). For example, you want to investigate the impact of vaccination (X) on infection with virus (Y) in a certain area to judge the effectiveness of the vaccine; but considering the different physiques of men and women, the vaccine may cause different resistance to the virus. , so gender (Z) is analyzed as a hierarchical item. This can be analyzed using the stratified chi-square test.

For hierarchical chi-square, a lot of theoretical knowledge is involved, as explained in the following table:

Normally, first check the 'odds homogeneity test', if it shows significance (p value less than 0.05), it means there are confounding factors, that is, it is necessary Consider hierarchical items, that is, view the data results under different hierarchical items separately. On the other hand, if the 'odds homogeneity test' is not passed, it means that there are no confounding factors and no stratification items need to be considered, and the overall results can be reported (including chi-square test and OR value).

For more information on the stratified chi-square test, it is recommended to refer to the SPSSAU help manual. There is a lot of content and will not be explained here. https://spssau.com/helps/medicalmethod/layerchi.html

  1. Chi-square test analysis

The above introduces the five types of chi-square tests and their simple analysis process. Next, we will introduce the analysis process of the chi-square test in detail through a specific example of the chi-square test. IncludingThe data format required for the chi-square test, the operation of the software, the detailed interpretation of the analysis results, the comparison of specific differences, the analysis of effect sizes, how to analyze multiple comparisons, etc..

  1. Data Format

When using software to perform chi-square test analysis, you need to pay attention to the data format of the chi-square test. Generally speaking, it can be divided into three types, namely regular format, weighted format, and contingency table format.

  1. General format
    One row represents a sample, and one column represents an attribute. Just list all the original data information, and use numbers to represent the categories of classified data, as shown in the figure below :

  1. Weighted format
    In actual research, many times there is no original data. In this case, summary data, that is, data with weighted items, should be used. For example, in the picture below, X is divided into 2 categories, and Y is divided into 3 categories. One type has 2*3=6 combinations, and the data information only has 6 groups of summary items (ie, weighted items), which are 40, 10, and 20 respectively. , 30, 20, 50; equivalent to a total of 170 samples. If the regular format (i.e. non-weighted format) is used, there should be 170 lines at this time; but the weighted format only requires 6 lines to represent, as shown in the figure below :

  1. Contingency table format

The above two data formats are very commonly used. In addition, when using SPSSAU's Fisher chi-square for analysis, contingency table format data will also be involved. Its essence is also a type of weighted data, but it is directly input into the software in the form of a contingency table for analysis. When editing data, please note that cell A1 must be empty, and the data placed does not include total data. As shown below:

  1. Software operation

(1) SPSSAU location

SPSSAU provides different methods of chi-square test in the following 6 parts, as shown below:

①SPSSAU [General Method] -> [Crossover (Chi-Square)], the analysis here is the simplest, only the Chi-square test results and corresponding visual graphics are provided, and no additional indicators and calculation processes will be output.

②SPSSAU [Experimental/Hospital Research] module provides five types of chi-square tests: [chi-square test] [paired chi-square] [chi-square goodness of fit] [stratified chi-square] [Fisher chi-square].

(2) SPSSAU operation

Taking the R*C table chi-square test as an example, use the SPSSAU [Experimental/Medical Research] module [Chi-square test] for analysis.

Case background:A certain grade wants to study whether there is a difference between the academic performance (excellent, passing, failing) of key classes and ordinary classes, and where the specific differences lie. , the data collected are as follows:

Analysis:Obviously, this is a 2*3 table data chi-square test. From the known data, it can be seen that the data format is a weighted format, so the data is organized into the following format :

Upload the data to the SPSSAU system. In the [Experimental/Medical Research] module, select [Chi-square test] and drag the variables to the corresponding analysis box on the right. The operation is as follows:

[Tips]:In a practical sense, the chi-square test will distinguish between X and Y, but from an algorithmic perspective, it will not distinguish between X and Y. Different placement positions will only affect the output format of the table, but will not affect the chi-square test analysis results. When analyzing, you can choose "Percent (by column)" or "Percent (by row)". The difference between the two is whether the data in the table adds up to 100% by rows or adds up to 100% by columns. It is up to you to decide from a personal analysis perspective. There is no fixed standard and it will not affect the analysis results of the chi-square test.

3. Interpretation of results

The results of the chi-square test analysis of the data in this case are as follows:

(1) First look at the p value

First, check whether the p value is significant (p value is less than 0.05 or less than 0.01). If it is significant, it means that the null hypothesis should be rejected (the null hypothesis of the chi-square test is that there is no difference between the two certain categories of data). If the p-value is greater than 0.05, there is no difference and the analysis stops. The chi-square value in this case is 32.752, and the corresponding p-value is less than 0.01, indicating that the difference is significant, that is, there is a significant difference between the scores of ordinary classes and key classes.

(2) Comparison of specific differences

  • Comparison of percentages in brackets
    When there are significant differences in the analysis, the specific differences can be described by comparing the percentages in brackets in the chi-square test results. The sum of the data in this case is 100% by column. Specific analysis shows that: in ordinary classes, the highest proportion of passing students is 50%, and the minimum proportion of outstanding students is 23.684%. In key classes, the highest proportion of students with excellent grades was 64.516%, and the lowest proportion of students with failed grades was 16.129%. At the same time, it can also be combined with the SPSSAU visualization pattern for intuitive comparison, as shown below:


If you want horizontal comparison, you can also select "Percentage (by row)" during analysis, which I won't elaborate on here. In addition to using percentages in parentheses to specifically compare differences, you can also use effect size indicators to describe the magnitude of the difference.

  • Effect size indicator

The effect size indicator of the chi-square test is mainly used to analyze the magnitude of the difference between two or more categorical variables. Its value range is between 0 and 1. The larger the effect size value, the greater the magnitude of the difference. Usually The critical points for distinguishing small, medium and large effect sizes are: 0.20, 0.50 and 0.80 respectively.

The SPSSAU chi-square test will provide 5 types of effect size indicators by default. This article will not discuss the specific principles and calculation formulas of each indicator in depth. The SPSSAU output effect size indicator results are as follows:

The selection of effect size indicators needs to be combined with the crosstab type and data type. The selection criteria are as follows:

This case is a 2*3 table and the Cramer V indicator should be used. The Cramer V value is 0.405, indicating that there is a moderate difference between the scores of key classes and ordinary classes.

(3) Multiple comparisons

The result of the chi-square test can only tell whether there is an overall difference, and cannot compare the differences between two combinations. If you need to specifically compare the differences between two combinations, you need to use multiple comparisons for analysis. The number of multiple comparisons=C (number of X categories) * C (number of Y categories), for example, the X category is 3 and the number of Y categories is 5, then it is C(3,2)*C(5,2)=30 times.

In multiple comparisons, the Pearson chi-square test is usually used. However, as the number of multiple comparisons increases, the probability of a Type I error also increases. Therefore, it is recommended to perform analyzes using a corrected significance level (Bonferroni correction) at a significance level of 0.05. For example, if the number of pairwise comparisons is 3 times, then the Bonferroni corrected significance level is 0.05/3 times = 0.0167, that is, the p value needs to be compared with 0.0167, not 0.05.

For example, in this case, to analyze whether the specific difference is between excellence and passing, between excellence and failing, or between passing and failing, check the multiple comparison results as follows:

As can be seen from the table above, the differences between the grades of ordinary classes and key classes between failing and excellent, and between excellent and passing are all significant (the p value is less than the Bonferroni corrected significance level of 0.0167). The difference between failing and passing grades does not show significance, so it can be considered that the difference in grades between ordinary classes and key classes mainly lies in the number of excellent grades.

(4) Chi-square test statistic process value

When talking about the applicable conditions of the chi-square test earlier, I mentioned the selection of three types of chi-square statistics (non-professional players can ignore it). The [Chi-square test] results of the SPSSAU [Experimental/Medical Research] module will automatically output the chi-square test. The statistical process value is used to determine the chi-square statistic, as shown below:

Analyzing the above table, we can see that the data in this case is a 2*3 table, and the theoretical frequency E≥5 grid accounts for 100%, so Pearson chi-square is used, that is, the chi-square result output in this case is Pearson chi-square.

4. Application of Chi-square test

The chi-square test can not only be used for difference analysis, but also has different applications in other aspects. For example, it is used for questionnaire multiple-choice question analysis, screening variables before logistic regression analysis, visual analysis, and determining whether there is a linear trend, etc., which will be introduced next.

1. Multiple choice question analysis

Multiple-choice question analysis:Firstly, when analyzing the multiple-choice question separately, the Chi-square goodness-of-fit test< /span>, analyze whether the selected proportions of each option in the multiple-choice question are consistent, as shown below, which is the analysis result of SPSSAU multiple-choice question:

From the results of the chi-square goodness-of-fit test, we can see that there is a significant difference in the proportion of each option selected, and the percentage selection distribution is uneven (chi-square value is 225.749, p=<0.05).

Single-choice-multiple-choice analysis:When conducting cross-analysis between single-choice questions and multiple-choice questions, the chi-square test (specifically, Pearson chi-square) is also involved. As shown below, it is the SPSSAU single-select-multiple-select analysis results:

From the results of the chi-square test, it can be seen that for the multiple-choice questions with a total of 6 items, gender does not show significant differences, that is, there is no difference in the reasons why men and women choose courses.

In the same way, the multiple-choice-multiple-choice cross analysis also involves the chi-square test, which will not be described in detail here.

2. Logistic regression analysis

When the dependent variable Y is categorical data, logistic regression analysis should be used to study the impact of X on Y. When there are many independent variables, the independent variables should be screened first, and X that has an impact on Y should be selected and put into the regression model. When the independent variable is quantitative data, use analysis of variance or t-test to screen the variables; when X is categorical data, the chi-square test should be used to screen the variables. When screening, if you are afraid of missing important variables, you can appropriately enlarge the p value, such as using 0.1 or 0.15 as the standard and exclude variables with a p value greater than 0.15.

Example: Perform a chi-square test on the dependent variable Y and the categorical variables X1-X4 of binary logistic regression analysis. The results are as follows:

As can be seen from the above table, except for X4, the differences between X1, X2, X3 and Y are all significant. Then before performing logistic regression analysis, you need to consider whether it is necessary to include in the model.

3. Visual analysis

(1) Cross summary chart

The selected percentage difference of the chi-square test can be intuitively displayed through graphics. SPSSAU will also automatically output the corresponding cross chart when performing the chi-square test. The more basic ones include column charts, bar charts, stacked column charts, and stacked bars. Graphics etc.

The SPSSAU output cross graph is as follows. You can switch the graph display mode through the button in the upper right corner.

(2) Correspondence analysis

In addition to the basic column chart, the visual graphics related to the chi-square test also include the corresponding graph obtained in the corresponding analysis. If you want to use graphics to visually display the relationship, or you want to study the relationship between multiple categories of data and use graphics to visually display it, and you also need to see the specific relationship between categories. At this point, correspondence analysis can be used.

Correspondence analysis is a visual data analysis method that can display several sets of data with no apparent connection through a visually acceptable positioning map. The basic idea is to express the proportional structure of each element in the rows and columns of a contingency table in the form of points in a lower-dimensional space.

For example: To study the differences in brand preferences collected by people with different income levels, use the [Correspondence Analysis] of the SPSSAU [Questionnaire Research] module to conduct analysis. The analysis results include the "Correspondence Table" and "Correspondence Chart" as follows:

It can be seen that the analysis result of the correspondence table is the analysis result of the chi-square test.

Analysis of the corresponding graph:

①The farther away from the origin, the stronger the point expresses the ‘relationship amplitude’, which means that the point can better reflect the ‘relationship’.

②The closer the points are to each other, the stronger the correlation between them; the farther the points are to each other, the weaker the correlation is.

Analysis of the above figure shows that there is a strong relationship between the low-income group and mobile phone brands B and E; the middle-income group has a strong relationship with mobile phone brand D; the high-income group has a strong relationship between the three mobile phone brands A, C and F. There is a strong relationship between them. In addition, low income and B and E brands are far away from the origin, which means that the relationship between low income and B and E brands is very obvious.

4. Trend chi-square test for linear trend

The chi-square test can also be used to analyze the trend difference relationship of contingency table data. The specific method is the Cochran-Armitage trend chi-square test. For example, if you want to analyze whether the proportion of lung cancer will increase with age (age here is classified data in stages), you can use the Cochran-Armitage trend chi-square test for analysis.

Cochran-Armitage trend chi-square test is usually used in k*2 (or 2*k) contingency table structure, k is ordered categorical data, and 2 refers to two categories. If the p value is less than 0.05, it means that there is some trend change between the k groups; if the p value is greater than 0.05, it means that there is no trend change between the k groups.

When analyzing in SPSSAU [Chi-square test], the Cochran-Armitage trend chi-square test results will be output by default, as shown below:

As can be seen from the table above, the p-value of the trend chi-square test is greater than 0.05, indicating that the proportion of lung cancer in different age groups does not show a trend change. If there is a trend change, the percentages in the chi-square test results can be compared in detail.

5. Parametric testing and non-parametric testing

Many students don’t understand why the chi-square test is a non-parametric test. Let’s briefly add the content of parametric tests and non-parametric tests.

1. Basic description

Parametric testing is a method of estimating and testing population parameters such as mean or variance under the assumption that the sample population has a certain known distribution. The opposite of parametric testing is non-parametric testing. Non-parametric testing does not make assumptions about the overall distribution shape. At this time, comparisons between parameters cannot be made, but comparisons between distributions.

2. Comparison

(1) Comparison of inspection indicators

Parametric test: Assume that the data obeys a specific distribution, such as normal distribution, and the population parameters are known. Therefore, parametric tests usually focus on the difference between the sample mean and the population mean to test whether the sample data conforms to the expected distribution.

Non-parametric test: The data does not need to conform to a specific distribution, but the overall parameters are inferred based on the distribution of the data itself. Non-parametric tests usually focus on the order of data rather than specific values, such as median, quartile, etc..

(2) Comparison of advantages and disadvantages

Parameter test: The advantage is that when the conditions are met, the test efficiency is high. However, it has strict requirements on data. For example, parametric testing cannot be used for hierarchical data and non-deterministic data, and it requires that the distribution type of the data is known and the population variance is equal. Furthermore, parametric tests are not suitable when the sample size is small and the distribution is unknown. When the sample size is large enough, the parametric test method can also handle non-normally distributed data well, because the distribution of the sample mean is approximately normal distribution according to the central limit theorem.

Non-parametric test: The advantage is that it is not limited by the overall distribution, has no strict requirements on data, has a wide range of applications, is simple and easy to master. The disadvantage is that if non-parametric testing is used for data that meets the parametric testing conditions, the testing efficiency is lower than parametric testing. Non-parametric tests mainly use rank or signed rank instead of using original data, which will lose some information and reduce the efficiency of statistical testing, resulting in a greater probability of making type II errors than parametric tests. Additionally, nonparametric tests are often considered when the sample size is small and the distribution is unknown.

3. Comparison of commonly used methods

Commonly used methods are compared as follows:

4. Other methods of difference analysis

The chi-square test is used to analyze the difference between categorical data. If you want to analyze the difference between categorical and quantitative data, you should use analysis of variance or t-test for analysis. The comparison is as follows:

Guess you like

Origin blog.csdn.net/m0_37228052/article/details/134672629