如何计算python中二进制变量之间的相关性?

How to calculate correlation between binary variables in python?

两个二进制变量(x 和 y)在 pandas Dataframe 中为多个日期形成两列。我想计算 x 和 y 之间的相关分数,它量化 x=1 与 y=1 的相关程度(x=0 和 y=0)。

  1. 相关的什么定义是合适的?
  2. 有内置函数吗?


    |天| _x | _ y|

    0  | 1 | 1
    
    1  | 1 | 0
    
    2  | 0 | 0
    
    3  | 1 | 1
    

解释:这是两个分类。例如,x = 早餐吃了鸡蛋(0 或 1),y = 头痛(0 或 1)。还有几天的 x 和 y 数据,我想看看 'strongly correlated' 有鸡蛋和头痛是怎么回事。我知道 Pearson 的相关性在这里不适用。有什么用?

本例中使用的相关指标是 Pearson 的 rho。定义为两个二元变量,也称为皮尔逊相关系数。

rho = (n11*n00 -  n10*n01)/sqrt(n11.n10.n01.n00)
where 
n11 (n00) = number of rows with x=1(0) and y=1(0) etc. 

https://en.wikipedia.org/wiki/Phi_coefficient