After K-means, I am iterating over many files consists of tables, mostly are 3X3. Some of them with "0" elements inside cells but most of them aren't. I read that chi2_contingencycouldn't be used if zero appears inside one or two of the cells. What method should I use if for example I am trying to find where df1 is differently distributed than df3? // or df2 different from df1.. (using python) E.g of tables:

Cluster |df1  |df2  |df3 
0       |14   |20    |100
1       |1    |3     |75
2       |0    |1     |12
3       |2    |2     |48

Cluster     |df1  |df2    |df3 
    0       |9    |2      |32
    1       |3    |3      |4
    2       |5    |21     |199

Pard of code chisquare related (no errors but isn't the right calculation):

e2 = frame[['df1', 'df2', 'df3']]
            stat, p, dof, expected = chi2_contingency(e2)
  • $\begingroup$ yates correction for continuity is for 2 $\times$ 2 tables. $\endgroup$
    – mdewey
    Oct 26, 2020 at 16:53
  • $\begingroup$ So how does I ran it without any problems? what it does when I have a 0 element? and is it the right test anyway? $\endgroup$ Oct 26, 2020 at 17:37
  • $\begingroup$ It computes the expected frequency in the normal way I assume (I do not use python). It may or may not be the right test depending on your scientific question. $\endgroup$
    – mdewey
    Oct 26, 2020 at 18:19
  • $\begingroup$ Each df corresponding to a group. I am trying to find in which case, df1 will have a different distribution than df3 (according to clusters). df2 distribution should be different than df1 but it's not necessary $\endgroup$ Oct 26, 2020 at 18:39
  • $\begingroup$ A case where df1 will be mostly in cluster 1 while df3 in cluster 2 $\endgroup$ Oct 26, 2020 at 18:46


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.