# Chi-2, test of independance, Yates correction in R

I'm trying to run chi square - test of independance. Between Category A that include values 1,2,3 and Category 2 that include values from 1 to 12.

As you see, there is violation of the assumption that on cell should not have value inferior to 1 and total of cell with expected value inferior to 5 not exceed 20%. (in the Category A value 2)

actual=structure(c(12, 4.5, 10.5, 8, 30, 22.3333333333333, 23.5, 21.8333333333333,
17.5, 9.83333333333333, 10.1666666666667, 12, 182.166666666667,
1, 1, 2, 2.5, 0, 1.33333333333333, 1, 3.33333333333333, 7.5,
7.83333333333333, 7.66666666666667, 5, 40.1666666666667, 34,
40.5, 28.5, 36.5, 20, 19.3333333333333, 23.5, 15.8333333333333,
25, 27.3333333333333, 8.16666666666667, 16, 294.666666666667,
47, 46, 41, 47, 50, 43, 48, 41, 50, 45, 26, 33, 517), .Dim = c(13L,
4L), .Dimnames = list(c("1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "Sum"), c("1", "2", "3", "Sum")), class = c("table",
"matrix"))

expected=structure(c(16.56, 16.21, 14.45, 16.56, 17.62, 15.15, 16.91,
14.45, 17.62, 15.86, 9.161, 11.63, 182.181, 3.652, 3.574, 3.185,
3.652, 3.885, 3.341, 3.729, 3.185, 3.885, 3.496, 2.02, 2.564,
40.168, 26.79, 26.22, 23.37, 26.79, 28.5, 24.51, 27.36, 23.37,
28.5, 25.65, 14.82, 18.81, 294.69, 47.002, 46.004, 41.005, 47.002,
50.005, 43.001, 47.999, 41.005, 50.005, 45.006, 26.001, 33.004,
517.039), .Dim = c(13L, 4L), .Dimnames = list(c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "Sum"), c("1",
"2", "3", "Sum")))

chisq.test(actual)

Pearson's Chi-squared test

data:  actual
X-squared = 99.516, df = 22, p-value = 7.835e-12

Warning message:
In chisq.test(actual) :
approximation of Chi-2 may be incorrect

I Add correct=T to chisq.test but still not obtain the correction. Is my reasoning according these result is correct? And how to correct my datas that have value inf of 5 in R ?

Thanks a lot.

• Be clear on why you would use Yates' correction, e.g., are you trying to make the test more conservative like Fisher's exact test? Much has been written about this on the site. Dec 13, 2016 at 12:07
• I think it only implements Yates' correction for 2 by 2 tables. Why not try the option to simulate the $p$-values? Dec 13, 2016 at 13:19
• @Frank Harrell: My problem is the violation of the assumption the total of cell with expected value inferior to 5 should not exceed 20%. (in the Category A value 2). As I understood, when we are in this case we must notice that there is violation of this assumption or accept to lost datas by delete the concerned type of category (category A 2) or we could use Yates correction for these small values. Is it correct as approach ? thanks. Dec 13, 2016 at 13:19
• That is a myth as discussed elsewhere on the site. The expected frequency can be as small as 1.0 and the ordinary Pearson $\chi^2$ test still be quite accurate. Pearson made up the 5 without trying it out. Dec 13, 2016 at 13:32
• @mdewey : simulate as that chisq.test(actual, simulate.p.value = TRUE) ? But what additional information it brings to me ? thanks a lot. Dec 13, 2016 at 13:55

I recommend you to use Fisher's exact test instead. You might be getting this error because the expected count in one of your row-column intersections of the contingency table would be less than $$5$$ (or $$3$$). Fisher's exact test is used either when the sample size is small or when the data are highly imbalanced across categories. Chi-square approximation is based on the central limit theorem and therefore, large sample sizes are mandatory to undertake chi-square. Generate a contingency table of Categories A and B and then apply Fisher's exact test: