コード例 #1
0
def estimate(y, lik, K, M=None, verbose=True):
    from numpy_sugar.linalg import economic_qs
    from numpy import pi, var, diag
    from glimix_core.glmm import GLMMExpFam
    from glimix_core.lmm import LMM
    from limix._data._assert import assert_likelihood
    from limix._data import normalize_likelihood, conform_dataset
    from limix.qtl._assert import assert_finite
    from limix._display import session_block, session_line
    lik = normalize_likelihood(lik)
    lik_name = lik[0]
    with session_block("Heritability analysis", disable=not verbose):
        with session_line("Normalising input...", disable=not verbose):
            data = conform_dataset(y, M=M, K=K)
        y = data["y"]
        M = data["M"]
        K = data["K"]
        assert_finite(y, M, K)
        if K is not None:
            # K = K / diag(K).mean()
            QS = economic_qs(K)
        else:
            QS = None
        if lik_name == "normal":
            method = LMM(y.values, M.values, QS, restricted=True)
            method.fit(verbose=verbose)
        else:
            method = GLMMExpFam(y, lik, M.values, QS, n_int=500)
            method.fit(verbose=verbose, factr=1e6, pgtol=1e-3)
        g = method.scale * (1 - method.delta)
        e = method.scale * method.delta
        if lik_name == "bernoulli":
            e += pi * pi / 3
        v = var(method.mean())
        return g, v, e
コード例 #2
0
def estimate(y_phe, lik, kin, marker_mat=None, verbose=True):
    ''' estimate variance components '''
    lik = normalize_likelihood(lik)
    lik_name = lik[0]
    with session_block("Heritability analysis", disable=not verbose):
        with session_line("Normalising input...", disable=not verbose):
            data = conform_dataset(y_phe, M=marker_mat, K=kin)
        y_phe = data["y"]
        marker_mat = data["M"]
        kin = data["K"]
        assert_finite(y_phe, marker_mat, kin)
        if kin is not None:
            # K = K / diag(K).mean()
            q_s = economic_qs(kin)
        else:
            q_s = None
        if lik_name == "normal":
            method = LMM(y_phe.values, marker_mat.values, q_s, restricted=True)
            method.fit(verbose=verbose)
        else:
            method = GLMMExpFam(y_phe, lik, marker_mat.values, q_s, n_int=500)
            method.fit(verbose=verbose, factr=1e6, pgtol=1e-3)
        v_g = method.scale * (1 - method.delta)
        v_e = method.scale * method.delta
        if lik_name == "bernoulli":
            v_e += pi * pi / 3
        v_v = var(method.mean())
        return v_g, v_v, v_e
コード例 #3
0
k01 = kmaf01_pd.loc[kfilter, :]
k01 = k01.loc[:, kfilter]

kfilter = kmaf005_pd.index.isin(pc1.iloc[:, 0])
k005 = kmaf005_pd.loc[kfilter, :]
k005 = k005.loc[:, kfilter]

snps_kmaf01 = np.load("k2029_SNPs_MAF0.1_R20.5.npy")
snps_kmaf005 = np.load("k2029_SNPs_MAF0.05_R20.9.npy")

K = np.array(k01)

iscan_model = iscan(snps_kmaf01, pc1.iloc[:, 1], K=K, M=None)

from limix._data import asarray as _asarray, conform_dataset, normalize_likelihood
from limix._display import session_block
from limix.qtl._assert import assert_finite
from limix.qtl._result import IScanResultFactory
from numpy_sugar.linalg import economic_qs
from xarray import concat
from numpy import asarray, empty, ones

lik = normalize_likelihood("normal")
lik_name = lik[0]
y = pc1.iloc[:, 1]
M = np.ones((211, 2))
G = snps_kmaf01

k01 = np.array(k01)
K = k01iscan_model = iscan(G, y, K=k01, M=none)