InfluentialPoints.com Biology, images, analysis, design... 

"It has long been an axiom of mine that the little things are infinitely the most important" 

Pearson's chi square test of independenceOn this page: Models & study designs Largesample tests Exact tests using the X^{2} statistic AssumptionsModels & study designsThis test is used to assess whether paired observations on two (usually nominal) variables are independent of each other. It thus enables us to determine if there is a significant difference between two independent proportions. The frequencies in each category are arranged in a contingency table. The test statistic is Pearson's chi square statistic (X^{2}) as defined below. It's precise distribution depends on the sampling model. Multinomial modelThe original Pearson's chi square statistic assumes a multinomial model with only the total number of observations fixed. This can arise from two possible sampling designs:
A single random sample is taken (analytical survey) and individuals are classified according to two characteristics. For example we might take a random sample of 2000 adult men aged 1825 and determine whether each is married or single, and whether each is positive or negative for the HIV virus. We then compare the proportion of married men with the virus with the proportion of single men with the virus.
Individuals are randomly allocated to two treatment groups (completely randomized experimental design) and in each group the frequencies with and without a particular characteristic are recorded. For example, individuals with malaria are randomly allocated to two treatment groups in which patients are given either drug A or drug B. The proportion of patients suffering neuropsychiatric side effects is compared between drug A and drug B. Note that in practice most experiments use some form of restricted randomization so that numbers in each treatment group are (more or less) fixed (see below). Independent binomial modelIn the second model either row or column totals are fixed (giving a double binomial model), but the other marginal totals are free to vary.
Two random samples are taken (comparative area observational design) and in each sample the frequencies with and without a particular characteristic are recorded. For example, we take two random samples, one from a rural area and the other from an urban area, each of 1000 adult men. We then compare the proportion of infected men from rural areas with the proportion of infected men from urban areas. The same model applies for cohort or casecontrol designs, and randomized trials where restricted randomization is used to equalize group sizes for each treatment. The exact distributions of X^{2} obtained under the two different models differ somewhat. However the asymptotic distribution of the statistic for both models is chi square with
Large sample testsGeneral formulaThe test statistic  X^{2} known as Pearson's chi square  can be calculated from the following general formula:
This formula can also be used for goodness of fit tests and for contingency tables with more than two rows or columns. For 2 × 2 contingency tables there is an alternative computational formula that is preferred as it is less subject to rounding errors:
Note that for the 2 × 2 table the formulations given above are mathematically identical to the square of the statistic obtained in the ztest for independent The value of X^{2} is referred to the probability calculator on your software package, or to a table of χ^{2} values at When the chi square test is used as a test of association it is naturally two sided since the null hypothesis is of no association versus the alternative of some association. However, when it is being used to compare two proportions (in other words for a 2 × 2 table), a onesided test might be required. This is obtained by simply halving the Pvalue given by Pearson's chi square statistic. Correction for continuityFor small sample sizes, many  but not all 
The Yates correction for the computational formula is shown below:
The correction is usually only recommended if the smallest expected frequency is less than 5. Note that the correction should not be applied if The 'n − 1' chisquare test
In 1947 Pearson recommended a third version of the chisquare test where n in the computational formula for the 2 × 2 table is replaced by n − 1.
We note that one statistical package (EpiInfo) describes this as the MantelHaenszel chisquare
Exact tests using the X^{2} statisticMultinomial Independent binomial Monte Carlo solutions We used this approach to compare our result with that given by Ludbrook (2008) for the independent binomial model (termed by Ludbrook the comparative trial or singly conditioned 2×2 table). Group 1 had 14 dead and 9 alive, so p_{1} = 0.6087. Group 2 had 17 dead and 2 alive so p_{2} = 0.8947. Ludbrook considered that the Pvalue of 0.044 obtained by the package Testimate for the singleconditioned option for exact tests on an odds ratio of 1, a risk ratio of 1 and a risk difference of 0 was acceptable. The Pvalue of 0.0391 obtained by StatXact for exact tests on a risk ratio of 1 and a risk difference of 0 was also deemed acceptable. Our exact Monte Carlo X^{2} test for these data with one million replicates gave a similar Pvalue of 0.0381.
AssumptionsSampling or allocation is randomFor model 1 (multinomial).Observations are independentObservations are assumed to be independent of each other. This assumption is not met if (for example) samples are obtained from clusters, or cluster randomization is used, and the test is then used to analyze results at an individual level. However, there is an approximate correction which can be applied to the chi square test for used with cluster samples which we cover in Errors are normally distributedBoth models assume errors are normally distributed. Providing the cell frequencies are reasonably large, cell values in a 2 × 2 table will be distributed normally about their expected values. If any expected frequency is less than 5, then providing you want a conventional Pvalue, the continuity correction should be applied. Omission of the continuity correction will give you a midPvalue. For very small sample sizes the conventional wisdom has been to use Fisher's exact test, although use of an exact test based on the correct model is now preferred. Mutual exclusivityA given case may fall only in one class. Related topics :G likelihood ratio testComparing survival rates
