polars_online.corr.equicorr

polars_online.corr.equicorr(r: Any) → float[source]

Compute the mean off-diagonal correlation of a matrix.

Use it to summarize a correlation matrix by one common correlation, the number a deco model tracks. For the same number from one standardized row, use equicorr_row(). For a common correlation per block, use block_means().

Parameters

r

A k x k correlation matrix, or a Gram or a closed group’s row, read as polars_online.gram.correlation() reads it, without the intercept (the module’s docstring says why). nan entries of an array are left out of the mean.

Returns

A float: the mean of the off-diagonal entries. It is nan below two columns, and where every off-diagonal entry is nan, with numpy’s RuntimeWarning.

Raises

ValueError

r is an array that is not square, or a Gram column other than the intercept has no variance.

Examples

r = np.array([[1.0, 0.4, 0.2], [0.4, 1.0, 0.3], [0.2, 0.3, 1.0]])
print(round(po.corr.equicorr(r), 3))
0.3

See also