limix.vardec.VarDec

class limix.vardec.VarDec(y, lik='normal', M=None)[source]

Variance decompositon through GLMMs.

Example

>>> from limix.vardec import VarDec
>>> from limix.stats import multivariate_normal as mvn
>>> from numpy import ones, eye, concatenate, zeros, exp
>>> from numpy.random import RandomState
>>>
>>> random = RandomState(0)
>>> nsamples = 20
>>>
>>> M = random.randn(nsamples, 2)
>>> M = (M - M.mean(0)) / M.std(0)
>>> M = concatenate((ones((nsamples, 1)), M), axis=1)
>>>
>>> K0 = random.randn(nsamples, 10)
>>> K0 = K0 @ K0.T
>>> K0 /= K0.diagonal().mean()
>>> K0 += eye(nsamples) * 1e-4
>>>
>>> K1 = random.randn(nsamples, 10)
>>> K1 = K1 @ K1.T
>>> K1 /= K1.diagonal().mean()
>>> K1 += eye(nsamples) * 1e-4
>>>
>>> y = M @ random.randn(3) + mvn(random, zeros(nsamples), K0)
>>> y += mvn(random, zeros(nsamples), K1)
>>>
>>> vardec = VarDec(y, "normal", M)
>>> vardec.append(K0)
>>> vardec.append(K1)
>>> vardec.append_iid()
>>>
>>> vardec.fit(verbose=False)
>>> print(vardec) 
Variance decomposition
----------------------

𝐲 ~ 𝓝(𝙼𝜶, 0.385⋅𝙺 + 1.184⋅𝙺 + 0.000⋅𝙸)
>>> y = exp((y - y.mean()) / y.std())
>>> vardec = VarDec(y, "poisson", M)
>>> vardec.append(K0)
>>> vardec.append(K1)
>>> vardec.append_iid()
>>>
>>> vardec.fit(verbose=False)
>>> print(vardec) 
Variance decomposition
----------------------

𝐳 ~ 𝓝(𝙼𝜶, 0.000⋅𝙺 + 0.350⋅𝙺 + 0.000⋅𝙸) for yᵢ ~ Poisson(λᵢ=g(zᵢ)) and g(x)=eˣ
__init__(y, lik='normal', M=None)[source]

Constructor.

Parameters
  • y (array_like) – Phenotype.

  • lik (tuple, "normal", "bernoulli", "probit", "binomial", "poisson") – Sample likelihood describing the residual distribution. Either a tuple or a string specifying the likelihood is required. The Normal, Bernoulli, Probit, and Poisson likelihoods can be selected by providing a string. Binomial likelihood on the other hand requires a tuple because of the number of trials: ("binomial", array_like). Defaults to "normal".

  • M (n×c array_like) – Covariates matrix.

Methods

__init__(y[, lik, M])

Constructor.

append(K[, name])

append_iid([name])

fit([verbose])

Fit the model.

lml()

Get the log of the marginal likelihood.

plot()

Attributes

covariance

Get the covariance matrices.

effsizes

Covariace effect sizes.

property covariance

Get the covariance matrices.

Returns

covariances – Covariance matrices.

Return type

list

property effsizes

Covariace effect sizes.

Returns

effsizes – Effect sizes.

Return type

ndarray

fit(verbose=True)[source]

Fit the model.

Parameters

verbose (bool, optional) – Set False to silence it. Defaults to True.

lml()[source]

Get the log of the marginal likelihood.

Returns

Log of the marginal likelihood.

Return type

float