I want to find the association between variables and Cramérs V works like a treat for matrices of sizes greater than 2$\times$2. However, for matrices with low frequencies, it does not work well. For the following contingency matrix, I get the result as 0.5. How can I account for the same?
1 2 a 2 0 b 0 2
Here is my code:
def cramers_stat(confusion_matrix): chi2 = ss.chi2_contingency(confusion_matrix) n = confusion_matrix.sum().sum() return np.sqrt(chi2 / (n*(min(confusion_matrix.shape)-1))) result=cramers_stat(confusion_matrix) print(result)
confusion_matrix is my input, in this case the matrix I mentioned above. I understand for good results, I need a matrix frequency above 5, but for perfect association as the case above I expected the result to be 1.