I have a large sparse matrix. now I want to make contingency table of all combination of pair of columns. For example : Let's say My sparse matrix is Mat
D1 D2 D3 D4 D5 .. Dn
1 0 1 0 0 .. 0
0 1 1 1 1 .. 1
.. .. .. .. .. .. ..
1 0 1 0 1 .. 1
Now need to make contingency tables for all combination of Di and Dj for example Contingency table for (D1,D2), (D1,D3), (D1,D4).. (D1, Dn), (D2,D3), (D2,D4) .. (D2,Dn) .. (Dn-1 , Dn)
structure of each Contingency Table
r1 r2
r3 r4
#where r1 is total number of 1's in Di column
# r2 is total number of 1's in Di AND Dj column
# r3 is total number of 1's in Di AND Dj column
# r4 is total number of 1's in Dj column
Also:
for each i in (1:n-1) {
for each j in (i+1 : n) {
Calculate r1,r2,r3,r4
create contingency table for Ri and Rj
apply fisher test on that
}
}
I want some fast implementation as it is taking more than 2-3 days
Here is one idea to get all the 2 x 2 matrices,
DATA
Or similarly,