Problem
Imagine I have a list of categorical labels: A A A B C C B B B C C A C C
. I want to calculate a numerical measure that characterizes how ordered it is. So perfectly ordered lists, where there is no mixing between labels of different kind, like A A A A B B B B C C C C
or C C C C C B B B B B A A A A A
and so forth should get a score of e.g. 1. On the other hand, random lists where probability of each next label in a sequence only depends on its overall frequency should get a score of e.g. 0.
Possible approaches
I thought about calculating pairwise distances (e.g. Hamming) between my sequence, random sequences and perfectly ordered sequences of the same length. Then I can use MDS to project them on 2D space and find "order axis" along which I can then calculate distance.
I can also come up with some sort of heuristic measures, like counting the number of different types of labels in a sliding window or for each label in the sequence calculating the distance to the closest label of the same kind.
Can I fit some sort of stochastic process to it and measure its memory? Just a wild idea.
Seems like this should be a trivial problem, but I couldn't find any out-of-the-box solutions.
Context
I have a dataset N_drugs x N_genes
. Each drug belongs to a specific functional group - hence the categorical labels. I want to select a subset of genes that will allow the best separation between different functional groups of the drugs. The actual data are vectors of logarithmic changes (treated condition vs non-treated condition) and therefore cosine similarity is the most natural distance metric. So at the end I get a N_drugs x N_drugs
distance matrix that I order using hierarchical clustering. Resulting order of labels (functional groups) is what I am trying to evaluate. Hope it makes sense.
Thank you in advance for any comments or suggestions.