I am working with some correlated binary files. I want to know, what is your opinion for calculating the correlation between binary vectors? for example, if I have two binary vectors X1 and X2 generating by a uniform distribution, as follows: X1=(1 0 0 1 1 1 0 ) X2=(1 0 1 1 1 0 1 ) Since they have the same bits in the exact 4 position of this 7 bits, can we say the correlation between these two vectors is 4/7?


  • 2
    $\begingroup$ You have computed $(1+\rho)/2$ instead of $\rho.$ Obviously both give equivalent information--just be careful that you interpret your statistic correctly and report it clearly. $\endgroup$ – whuber Aug 3 '18 at 21:00
  • $\begingroup$ Thanks for your answer. Would you please explain why you say that I consider (1+ρ)/2 instead of ρ in this way? I appreciate it $\endgroup$ – Bonnie Aug 3 '18 at 21:50
  • $\begingroup$ @whuber for which definition of rho? Not for Pearson. $\endgroup$ – Has QUIT--Anony-Mousse Aug 4 '18 at 10:10
  • 1
    $\begingroup$ @Anony Yes, for Pearson. The linear transformation $x\to 2x-1$ preserves correlation and recodes the values as $\pm 1.$ The uniformity assumption implies the mean is $0.$ Thus the Pearson coefficient is the expected product of the recoded values, equal to the number of matches minus the number of mismatches, as claimed by zipzapboing below. The number of mismatches, $m,$ is $n$ minus the number of matches, $M.$ All I am asserting is that $$M/n=\left(1+\frac{M-m}{n}\right)/2 = \left(1+\frac{M-(n-M)}{n}\right)/2,$$ which is readily verified. $\endgroup$ – whuber Aug 4 '18 at 12:26
  • $\begingroup$ @whuber but doesn't one usually use the sample mean of the two vectors rather than the theoretical mean? The usual r in the example would be 0.0913 $\endgroup$ – Has QUIT--Anony-Mousse Aug 4 '18 at 18:11

Avoid the term "correlation" for anything that does not have the expected value 0 for independent data, and a range of -1 to +1.

When people read correlation, they'll expect the Pearson correlation coefficient (or Spearman, which is Pearson after a rank transform).

Simple Matching Coefficient (SMC)

This coefficient is the number of bits in common (both 0 or both 1) over the total length. It's closely related to Hamming distance on bit strings. That is exactly what you have been computing, so why not use the name SMC?

Alternatively, you could also use actual Pearson Correlation, or the Jaccard index (which does not take 0s into account if both agree).

  • $\begingroup$ Thank you for your great explanation. Actually, maybe this SMC coefficient makes more sense in the application of my algorithm I should read about it more.Thank you $\endgroup$ – Bonnie Aug 4 '18 at 16:52

No. If I toss some coins, I would have $X_1 = \text{(1 if head, 0 if tail)}$ and $X_2 = (\text{1 if tail, 0 if head})$. Your method would say $\text{Cor}(X_1,X_2) = 0$ because they never match, but we know one predicts the other perfectly by being its opposite, so the correlation should be $-1$.

You want to use

$$\text{Cor}(X_1,X_2) = {\text{# matches} - \text{# mismatches} \over \text{# comparisons}}$$

  • $\begingroup$ Yes, that would be appropriate. $\endgroup$ – zipzapboing Aug 3 '18 at 22:19
  • $\begingroup$ Thank you for the answer. I totally agree with that part that you said we know one predicts since it is binary but I did not know how I should show that effect. Actually, I thought Cor(X1,X2)=# matches/ #comparisons which means in my example Cor(X1,X2)=4/7 but as far as I understand, based on the formula that you have written, Cor(X1,X2)=4-3/7=1/7 right? Sorry, I'm not expert, I just wanted to be sure that I got your point right. $\endgroup$ – Bonnie Aug 3 '18 at 22:21
  • $\begingroup$ could you please tell me how would it be calculated among more than two vectors? I mean for example correlation between 100 binary vectors $\endgroup$ – Bonnie Aug 3 '18 at 22:25
  • $\begingroup$ @Bonnie Correlation is a pairwise function, afaik there does not exist a natural generalization to more than two vectors $\endgroup$ – jon_simon Aug 4 '18 at 2:08
  • 2
    $\begingroup$ Bonnie, have you noticed that $(1 + 1/7)/2 = 4/7$? The value of $1/7$ is the Pearson correlation, as explained in comments to your question. $\endgroup$ – whuber Aug 4 '18 at 14:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.