I am unsure how to do this properly. I have two binary data sets, i.e. values in each data set is either 1 or 0. I now wish to see if they are in any way correlated. I could use Pearson's, but I don't know if that is applicable to binary data as well ?

Basically I just have data that looks something like this:

x = [1, 0, 0, 0, 0, 0, 1, 1, 1, 0]
y = [1, 0, 0, 0, 1, 0, 1, 0, 1, 0]

What I am trying to do is check whether my colleague is correct or not. He has stated that some particular set of data correlates with another set of data, and he therefore wants to discard/remove data points corresponding to where the value is 1 in x, i.e. 40% here. So that would mean I would reduce (in this example) my data with 4 cases. So before doing that I just want to make sure that he/we are correct.

  • $\begingroup$ I'm not sure I've fully understood, because x and y are correlated, your colleague wants to delete all data points where x=1 ? He effectively wants to recast the data as y=y[x!=1] and x=x[x!=1] ? Why is this a logical thing to do if x and y are correlated? $\endgroup$
    – gazza89
    Sep 19, 2018 at 13:36
  • $\begingroup$ Basically some of the data we have is used for model fitting, i.e. getting some parameters for this model. So this model should be able to calculate an expected outcome if the data used is similar to ours. However, he says that the above data correlates with the observed outcome (not the predicted that our model has to predict). So in order to get a model that is more correct on most data, the best thing would be to remove it. So it's like if I want to figure out if longer legs means greater running speed. But if some people only have one leg, that would not represent it well in this case. $\endgroup$ Sep 19, 2018 at 13:51
  • $\begingroup$ I still can't say I understand. In that analogy, is x "number of legs", y "running speed" and the thing you're trying to predict is "time taken to run 100m" ? And you only want to predict the target for people with two legs? Then it's trivial, you throw away all data points for people with 1 leg. I suspect however, what your colleague is saying is that x and y are correlated so using both contains redundant information? This isn't a problem per so, plenty of classifiers can deal with correlated features very naturally (e.g. decision trees) $\endgroup$
    – gazza89
    Sep 19, 2018 at 13:55
  • $\begingroup$ Yes, okay, that was indeed a bad example from me. This is not as straightforward as just one leg... I'll rephrase. Let's assume y is some kind of observed side effect. My colleague then says that there is a large correlation between people with side effects and some drug they have taken. The idea is, since it is strongly correlated, that we just throw away patients where we know they have received this drug pre-treatment since that would probably skew the overall model fitting. $\endgroup$ Sep 19, 2018 at 14:08
  • $\begingroup$ if y is a side effect, is x a pre-treatment, and you only want to model your target variable for people who did not receive the pre-treatment ? $\endgroup$
    – gazza89
    Sep 19, 2018 at 14:27

2 Answers 2


Usually for counts data such as yours you would go with a Fisher test or Chi-square test if the sample is large enough. Alternatively you could do something like https://en.wikipedia.org/wiki/Phi_coefficient .

  • $\begingroup$ I have +1000 samples, so that should be sufficient ? And is one test more preferable over the other, or should I just do both ? $\endgroup$ Sep 19, 2018 at 13:27
  • 1
    $\begingroup$ Your computer should be able to handle the Fisher test given your sample size, if not the Chi-square is a good approximation. Given your sample size the differences should be minimal. $\endgroup$ Sep 19, 2018 at 13:30

Chi square test of significance will let you know whether there exist significant relation amongst two or not. The amount of significance is not explained by chi square (very strong, strong, mild, weak,etc).

You need to plot bar stacked chart in order to get the idea about how significant two observation are(X and Y).

I did this in python to know whether there exist a relationship amongst two or not and then if it shows significant relationship then to check the significance I plot bar stacked plot


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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