rheon.gram.correlation

rheon.gram.correlation(g: Gram) → Any[source]

Compute the correlation matrix of a Gram’s columns from their co-moments.

Use it to read how a Gram’s columns move together, or to pass a correlation matrix on to rheon.corr, whose functions read a Gram this way themselves. To judge whether a fit on the columns is determined, use vif() or condition().

Parameters

g

The Gram, as gram() returns it, in any of its forms.

Returns

A k x k float array, with k the number of columns: C_ij / sqrt(C_ii C_jj) from the co-moments C. Its entries are nan in the row and the column of a constant column, the intercept included: a constant has no correlation with anything, and reporting 0 there would read as “independent”. The diagonal is 1, to rounding, where the variance is above 0.

Examples

This code reads df from Example data:

spec = rp.spec.ew_cov("cov", features=["x0", "x1", "x2"], half_life=100.0)
bank = rp.ModelBank([spec])
bank.fit_predict(df)
g = bank.gram("cov")[0]
print(g["columns"])
print(rp.gram.correlation(g).round(2))
['x0', 'x1', 'x2']
[[ 1.    0.16  0.08]
 [ 0.16  1.   -0.01]
 [ 0.08 -0.01  1.  ]]

See also

Notes

The diagonal is C_ii / sqrt(C_ii)**2, which came within 2.2e-16 of 1 on 200 random matrices.