LMMยถ
- class glimix_core.lmm.LMM(y, X, QS=None, restricted=False)[source]ยถ
Fast Linear Mixed Models inference via maximum likelihood.
Examples
>>> from numpy import array >>> from numpy_sugar.linalg import economic_qs_linear >>> from glimix_core.lmm import LMM >>> >>> X = array([[1, 2], [3, -1]], float) >>> QS = economic_qs_linear(X) >>> covariates = array([[1], [1]]) >>> y = array([-1, 2], float) >>> lmm = LMM(y, covariates, QS) >>> lmm.fit(verbose=False) >>> print('%.3f' % lmm.lml()) -3.649
One can also specify which parameters should be fitted:
>>> from numpy import array >>> from numpy_sugar.linalg import economic_qs_linear >>> from glimix_core.lmm import LMM >>> >>> X = array([[1, 2], [3, -1]], float) >>> QS = economic_qs_linear(X) >>> covariates = array([[1], [1]]) >>> y = array([-1, 2], float) >>> lmm = LMM(y, covariates, QS) >>> lmm.fix('delta') >>> lmm.fix('scale') >>> lmm.delta = 0.5 >>> lmm.scale = 1 >>> lmm.fit(verbose=False) >>> print('%.3f' % lmm.lml()) -3.832 >>> lmm.unfix('delta') >>> lmm.fit(verbose=False) >>> print('%.3f' % lmm.lml()) -3.713
Notes
The LMM model can be equivalently written as
๐ฒ โผ ๐(๐๐ท, ๐ ((1-๐ฟ)๐บ + ๐ฟ๐ธ)),
and we thus have vโ = s (1 - ๐ฟ) and vโ = s ๐ฟ. Consider the economic eigendecomposition of ๐บ:
๐บ = [๐โ ๐โ] [๐โ ๐] [๐โแต] [ ๐ ๐] [๐โแต]
and let
- ๐ณ = [(1-๐ฟ)๐โ + ๐ฟ๐ธโ ๐ ]
[ ๐ ๐ฟ๐ธโ].
In order to eliminate the need of ๐โ, note that ๐๐แต = ๐ธ implies that
๐โ๐โแต = ๐ธ - ๐โ๐โแต.
We will need to solve ((1-๐ฟ)๐บ + ๐ฟ๐ธ)๐ฑ = ๐ฎ for ๐ฑ. Let ๐ณโ = ((1-๐ฟ)๐โ + ๐ฟ๐ธโ) and let us define
๐ฑ = ๐โ๐ณโโปยน๐โแต if ๐ฟ=0, and ๐ฑ = ๐โ๐ณโโปยน๐โแต + ๐ฟโปยน(๐ธ - ๐โ๐โแต) if ๐ฟ>0.
We therefore have
๐ฑ = ๐ฑ๐ฎ.
Methods
__init__
(y,ย X[,ย QS,ย restricted])Constructor.
covariance
()Covariance of the prior.
fit
([verbose])Maximise the marginal likelihood.
fix
(param)Disable parameter optimization.
get_fast_scanner
()Return
FastScanner
for association scan.gradient
()Not implemented.
lml
()Log of the marginal likelihood.
mean
()Mean of the prior.
unfix
(param)Enable parameter optimization.
value
()Internal use only.
Attributes
X
Covariates matrix.
beta
Fixed-effect sizes.
beta_covariance
Estimates the covariance-matrix of the optimal beta.
delta
Variance ratio between
K
andI
.name
Name of this function.
ncovariates
Number of covariates.
nsamples
Number of samples.
scale
Scaling factor.
v0
First variance.
v1
Second variance.