3
$\begingroup$

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?

$\endgroup$
2
  • 3
    $\begingroup$ 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. $\endgroup$ May 7, 2014 at 21:59
  • $\begingroup$ 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? $\endgroup$
    – Glen_b
    May 7, 2014 at 22:52

1 Answer 1

6
$\begingroup$

If you give chisq.test a matrix of counts, it's going to assume that it's a matrix of observed counts and will perform a chi-square test of independence. If you want to perform a chi-square goodness of fit test, which seems to be what you want to do, then you would need to use the command

chisq.test(x,p)

where x is the vector of observed counts c(11, 44233), and p is the vector of probabilities from the null hypothesis that were used to calculated the expected counts.

$\endgroup$
3
  • 1
    $\begingroup$ Yeah, yikes. I wish the two tests had different function calls---I would definitely have preferred an error to be thrown for what I was trying to do given the way I entered it. $\endgroup$ May 8, 2014 at 16:14
  • $\begingroup$ 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)). $\endgroup$ May 8, 2014 at 21:38
  • $\begingroup$ fisher.test will perform a test analogous to the chi-square test of independence but not the chi-square goodness of fit test. $\endgroup$
    – jsk
    May 8, 2014 at 22:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.