pointBiserialCorrelation
Computes the point-biserial correlation between a binary variable and a continuous variable.
The point-biserial correlation measures the strength and direction of the association between a dichotomous (two-category) variable and a continuous variable. It is mathematically equivalent to the Pearson correlation when the binary variable is coded as 0 and 1. The binary variable x may use any two distinct finite values — they are automatically remapped so that the smaller value becomes 0 and the larger becomes 1, ensuring a consistent sign convention.
Delegates to pearsonCorrelation after remapping, so the p-value is computed using the same numerically stable t-test with (1-r)(1+r) cancellation avoidance.
Returns Double.NaN for both coefficient and p-value when the continuous variable has zero variance (all values identical).
Example:
val group = doubleArrayOf(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)
val score = doubleArrayOf(2.1, 3.4, 2.8, 7.5, 8.1, 6.9)
val result = pointBiserialCorrelation(group, score)
result.coefficient // 0.9808 (strong positive association)
result.pValue // 0.00002
result.n // 6Return
a CorrelationResult containing the point-biserial r, two-sided p-value, and sample size.
Parameters
the binary variable. Must contain exactly 2 distinct finite values. Non-finite values (NaN, Inf) are skipped during the distinct-value scan but passed through to Pearson, where they propagate as NaN.
the continuous variable, must have the same size as x.
Throws
if there are fewer than 3 observations.
Computes the point-biserial correlation between a boolean variable and a continuous variable.
The point-biserial correlation measures the strength and direction of the association between a dichotomous (two-category) variable and a continuous variable. This overload accepts a BooleanArray where false is mapped to 0.0 and true to 1.0, then delegates to pearsonCorrelation.
When all boolean values are the same (all true or all false), the binary variable has zero variance, and both coefficient and p-value are Double.NaN.
Example:
val passed = booleanArrayOf(false, false, false, true, true, true)
val score = doubleArrayOf(2.1, 3.4, 2.8, 7.5, 8.1, 6.9)
val result = pointBiserialCorrelation(passed, score)
result.coefficient // 0.9808 (strong positive association)
result.pValue // 0.00002Return
a CorrelationResult containing the point-biserial r, two-sided p-value, and sample size.
Parameters
the binary variable as booleans (false = 0, true = 1).
the continuous variable, must have the same size as x.
Throws
if there are fewer than 3 observations.
Computes the point-biserial correlation between an integer-coded binary variable and a continuous variable.
The point-biserial correlation measures the strength and direction of the association between a dichotomous (two-category) variable and a continuous variable. This overload accepts an IntArray whose values are converted to Double and then validated as binary (must contain exactly 2 distinct finite values). The smaller value is mapped to 0 and the larger to 1.
Example:
val group = intArrayOf(0, 0, 0, 1, 1, 1)
val score = doubleArrayOf(2.1, 3.4, 2.8, 7.5, 8.1, 6.9)
val result = pointBiserialCorrelation(group, score)
result.coefficient // 0.9808 (strong positive association)
result.pValue // 0.00002Return
a CorrelationResult containing the point-biserial r, two-sided p-value, and sample size.
Parameters
the binary variable as integers. Must contain exactly 2 distinct values.
the continuous variable, must have the same size as x.
Throws
if there are fewer than 3 observations.