rheon.corr.equicorr_loglik

rheon.corr.equicorr_loglik(row: Any, rho: float) → float[source]

Compute the Gaussian log-density of a standardized row under a common correlation.

Use it to score, offline, a row against an equicorrelation matrix, the loglik a deco model writes. To estimate the common correlation from the row, use equicorr_row().

Parameters

row

One row of n standardized values.

rho

The common correlation, every off-diagonal entry of the matrix R. Inside (-1/(n-1), 1) R is positive definite.

Returns

A float, in closed form with S1 = sum(x) and S2 = sum(x * x) over the row x:

det R    = (1 - rho)**(n-1) * (1 + (n-1) rho)
x'R^-1 x = (S2 - rho S1**2 / (1 + (n-1) rho)) / (1 - rho)
loglik   = -0.5 * (n log(2 pi) + log det R + x'R^-1 x)

It is nan below two entries, and outside (-1/(n-1), 1), where R is not positive definite.

Examples

row = [1.2, 0.8, 1.0, -0.2]
independent = rp.corr.equicorr_loglik(row, 0.0)
common = rp.corr.equicorr_loglik(row, 0.4)
print(round(independent, 3), round(common, 3))
-5.236 -4.716

See also