scipy.stats.

pointbiserialr#

scipy.stats.pointbiserialr(x, y)[原始碼]#

計算點二系列相關係數及其 p 值。

點二系列相關用於衡量二元變數 x 和連續變數 y 之間的關係。與其他相關係數一樣,此係數介於 -1 和 +1 之間,0 表示沒有相關性。-1 或 +1 的相關性表示決定性關係。

此函數可以使用快捷公式計算,但產生與 pearsonr 相同的結果。

參數::
xarray_like of bools

輸入陣列。

yarray_like

輸入陣列。

回傳值::
res: SignificanceResult

一個包含屬性的物件

statisticfloat

R 值。

pvaluefloat

雙尾 p 值。

註解

pointbiserialr 使用自由度為 n-1 的 t 檢定。它等同於 pearsonr

點二系列相關的值可以從下式計算:

\[r_{pb} = \frac{\overline{Y_1} - \overline{Y_0}} {s_y} \sqrt{\frac{N_0 N_1} {N (N - 1)}}\]

其中 \(\overline{Y_{0}}\)\(\overline{Y_{1}}\) 分別是編碼為 0 和 1 的度量觀測值的平均值;\(N_{0}\)\(N_{1}\) 分別是編碼為 0 和 1 的觀測值數量;\(N\) 是觀測值總數,\(s_{y}\) 是所有度量觀測值的標準差。

顯著異於零的 \(r_{pb}\) 值完全等同於兩組之間平均值的顯著差異。因此,可以使用自由度為 \(N-2\) 的獨立組別 t 檢定來檢驗 \(r_{pb}\) 是否非零。比較兩個獨立組別的 t 統計量與 \(r_{pb}\) 之間的關係由下式給出:

\[t = \sqrt{N - 2}\frac{r_{pb}}{\sqrt{1 - r^{2}_{pb}}}\]

參考文獻

[1]

J. Lev, “The Point Biserial Coefficient of Correlation”, Ann. Math. Statist., Vol. 20, no.1, pp. 125-126, 1949.

[2]

R.F. Tate, “Correlation Between a Discrete and a Continuous Variable. Point-Biserial Correlation.”, Ann. Math. Statist., Vol. 25, np. 3, pp. 603-607, 1954.

[3]

D. Kornbrot “Point Biserial Correlation”, In Wiley StatsRef: Statistics Reference Online (eds N. Balakrishnan, et al.), 2014. DOI:10.1002/9781118445112.stat06227

範例

>>> import numpy as np
>>> from scipy import stats
>>> a = np.array([0, 0, 0, 1, 1, 1, 1])
>>> b = np.arange(7)
>>> stats.pointbiserialr(a, b)
(0.8660254037844386, 0.011724811003954652)
>>> stats.pearsonr(a, b)
(0.86602540378443871, 0.011724811003954626)
>>> np.corrcoef(a, b)
array([[ 1.       ,  0.8660254],
       [ 0.8660254,  1.       ]])