ordinalcorr.biserial_corr¶
- ordinalcorr.biserial(x: ArrayLike, y: ArrayLike) float[source]¶
Compute the biserial correlation coefficient between a continuous variable \(x\) and a dichotomized variable \(y\in\{0,1\}\), assuming \(y\) is generated by discretizing a latent continuous variable.
- Parameters:
x (array-like) – Continuous variable.
y (array-like) – Dichotomous variable, assumed to be derived from a latent continuous variable.
- Returns:
Biserial correlation coefficient.
- Return type:
float
Examples
>>> from ordinalcorr import biserial >>> x = [0.1, 0.2, 0.3, 0.4, 0.5] >>> y = [0, 0, 1, 1, 1] >>> round(biserial(x, y), 4) 1.0982
- Details:
The biserial correlation coefficient is defined as:
(1)¶\[r_{b} := r_{pb} \frac{\sqrt{p (1 - p)}}{\phi(z)}\]where
\(r_{pb}\) is the point-biserial correlation coefficient (equivalent to Pearson’s correlation coefficient between \(X\) and the dichotomous \(Y\))
\(p\) is the proportion of observations where \(Y = 1\)
\(\phi(z)\) is the probability density function of the standard normal distribution
\(z\) is the \(p\)-th quantile (percentile point) of the standard normal distribution, i.e. \(\Phi(z) = p\).
It is known that Pearson’s product-moment correlation coefficient between \(X\) and dichotomized \(Y\) underestimates the true correlation (attenuation of correlation) [1] [2]. Therefore, the biserial correlation coefficient corrects it by the inverse of the amount of attenuation \(\frac{\sqrt{p (1 - p)}}{\phi(z)}\).
Some literature uses the following definition:
\[r_{b} := \frac{\bar{X}_1 - \bar{X}_0}{s_X} \frac{p (1 - p)}{\phi(z)}\]where
- \(\bar{X}_1\) and \(\bar{X}_0\) are the means of the continuous variable for the two categories of the dichotomous variable
\(\bar{X}_1 = \frac{1}{n_1} \sum_{i:Y_i = 1} X_i, \quad n_1 = |\{i: Y_i = 1\}|\)
\(\bar{X}_0 = \frac{1}{n_0} \sum_{i:Y_i = 0} X_i, \quad n_0 = |\{i: Y_i = 0\}|\)
- \(s_X\) is the standard deviation of the continuous variable
\(s_X = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (X_i - \bar{X})^2}, \quad n = n_1 + n_0\)
This is equivalent to the equation (1).
References