I have data like this:
c1 c2 c3 c4 c5
r1 a a b c d
r2 NA a b c a
r3 NA b b b c
r4 a b c b c
Here, each row is a data record, each column is a feature. I have several thousand such matrices, sizes range from 10-100 rows and most have around 50 columns. In this data NA
entries must be treated as missing / not distinguishable from non-NA values; it is not possible to simply ignore rows and columns where NAs occur.
My goal is to figure out, for each matrix, how many columns do I really need to distinguish / discriminate each row from the other rows, and which set(s) of column(s) achieve that? For example, in the matrix given above, columns c3
and c5
together are enough to discriminate all four rows.
To me this seems like a two-step problem: the first question ("how many columns are needed to distinguish all rows from each other?") seems akin to finding matrix rank, but I'm not sure how to do that with nominal data. I'm considering recoding each value as a power of two (with NA
as 0
), then doing something like gaussian elimination but where the coefficient of each row can only be 0 or 1. I've not yet convinced myself that that will work though, so before I do that, I wanted to ask if anyone knows a better approach or can spot an obvious pitfall that will make my approach fail.
For the second question ("which set(s) of columns sufficiently encode the fact that all rows are distinct?"), I only care about finding the smallest such solutions, not all solutions. So for the example above, the solution "c3,c5" is all I want, I don't care about solutions like "c3,c4,c5" where extra, redundant information is included. I do however expect some cases where there are multiple "equally minimal" solutions. For this part of the problem I've already implemented a brute-force-ish approach and I'm content to use it, as long as I can know in advance what number of columns is needed. But I am of course also open to suggestions on how to do that part more efficiently.