# chisq.test in R doesn't produce same answer as by-hand [duplicate]

I have the following set of observed versus expected values:

> chisq.test(matrix(c(35,11,44209,44233), nrow=2))
[,1]  [,2]
[1,]   35 44209
[2,]   11 44233


Where [1,1] = expected yes, [1,2] = expected no, [2,1] = observed yes, [2,2] observed no.

When I run this, I get...

    Pearson's Chi-squared test with Yates' continuity correction

data:  matrix(c(35, 11, 44209, 44233), nrow = 2)
X-squared = 11.506, df = 1, p-value = 0.0006937


So, the $\chi^2 =11.506$.

However, when I hash it out by hand, I get

> (11-35)^2/35 + (44233-44209)^2/(44209)
[1] 16.47017


...which is considerably larger. What is the cause of this difference? Is this the Yates continuity correction in action? Am I entering the data incorrectly somehow? I see the function definition is overloaded in that it does both contingency table tests /and/ goodness-of-fit tests, but this looked like the right syntax for contingency function?

• Yes, it is because of the continuity correction, do chisq.test(matrix(c(35,11,44209,44233), nrow=2),correct=F) to do the test without it. Also if I remember correctly the matrix upper row should contain observed, and the lower should contain expected. May 7, 2014 at 21:59
• I see at least two differences (it's doing a 2x2 independence test with continuity correction, and you're not doing either of those things), but I'm not 100% sure what you're calculating. How do your expected values arise? May 7, 2014 at 22:52

chisq.test(x,p)

• Also, just to confirm, this is different than the fisher.test() syntax, right? Which does actually take the form of... fisher.test(matrix(c(35,11,44209,44233), nrow=2)). May 8, 2014 at 21:38