Example Chi Square test - why different answers from HypothesisTests and Distances?

I think you need to clarify what Chi-Square test do you want to perform, goodness of fit or a contingency table?

If you run your own code to estimate the goodness of fit

sum(((Obs-Exp).^2./Exp))

you obtain the 5.2 answer.
I can reproduce this answer by running

using HypothesisTests
ChisqTest(O)

with the correct degrees of freedom, 9.

By testing both O and E, you’re really running a long goodness of fit, where the deviations occur only in O, noe in E, obtaining the same Chi Square value, but different degrees of freedom.

I assume the code in Distances tests a contingency table too.

5 Likes