scipy.stats.pointbiserialr¶
- scipy.stats.pointbiserialr(x, y)[source]¶
Calculates a point biserial correlation coefficient and its p-value.
The point biserial correlation is used to measure the relationship between a binary variable, x, and a continuous variable, y. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply a determinative relationship.
This function uses a shortcut formula but produces the same result as pearsonr.
Parameters: x : array_like of bools
Input array.
- y : array_like
Input array.
Returns: correlation : float
R value
- pvalue : float
2-tailed p-value
- rac{overline{Y_{1}} -
- overline{Y_{0}}}{s_{y}}sqrt{
rac{N_{1} N_{2}}{N (N - 1))}}
Where \(Y_{0}\) and \(Y_{1}\) are means of the metric observations coded 0 and 1 respectively; \(N_{0}\) and \(N_{1}\) are number of observations coded 0 and 1 respectively; \(N\) is the total number of observations and \(s_{y}\) is the standard deviation of all the metric observations.
A value of \(r_{pb}\) that is significantly different from zero is completely equivalent to a significant difference in means between the two groups. Thus, an independent groups t Test with \(N-2\) degrees of freedom may be used to test whether \(r_{pb}\) is nonzero. The relation between the t-statistic for comparing two independent groups and \(r_{pb}\) is given by:
\[t = \sqrt{N - 2}\]rac{r_{pb}}{sqrt{1 - r^{2}_{pb}}}
Examples
>>> 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. ]])