limix.qc.normalise_covarianceΒΆ
- limix.qc.normalise_covariance(K, out=None)[source]ΒΆ
Variance rescaling of covariance matrix πΊ.
Let n be the number of rows (or columns) of πΊ and let mα΅’ be the average of the values in the i-th column. Gower rescaling is defined as
\[πΊ(n - 1)/(πππππ(πΊ) - βmα΅’).\]Notes
The reasoning of the scaling is as follows. Let π be a vector of n independent samples and let π² be the Gowerβs centering matrix. The unbiased variance estimator is
\[v = β (gα΅’-αΈ‘)Β²/(n-1) = πππππ((π -αΈ‘π)α΅(π -αΈ‘π))/(n-1) = πππππ(π²π π α΅π²)/(n-1)\]Let πΊ be the covariance matrix of π . The expectation of the unbiased variance estimator is
\[π[v] = πππππ(π²π[π π α΅]π²)/(n-1) = πππππ(π²πΊπ²)/(n-1),\]assuming that π[gα΅’]=0. We thus divide πΊ by π[v] to achieve an unbiased normalisation on the random variable gα΅’.
- Parameters
K (array_like) β Covariance matrix to be normalised.
out (array_like, optional) β Result destination. Defaults to
None
.
Examples
>>> from numpy import dot, mean, zeros >>> from numpy.random import RandomState >>> from limix.qc import normalise_covariance >>> >>> random = RandomState(0) >>> X = random.randn(10, 10) >>> K = dot(X, X.T) >>> Z = random.multivariate_normal(zeros(10), K, 500) >>> print("%.3f" % mean(Z.var(1, ddof=1))) 9.824 >>> Kn = normalise_covariance(K) >>> Zn = random.multivariate_normal(zeros(10), Kn, 500) >>> print("%.3f" % mean(Zn.var(1, ddof=1))) 1.008