def test_lmm_lr(G, y, Z, Kbg, Covs=None): """ low-rank lmm input: G : genotypes y : phenotype Z : features of low-rank matrix Kbg : background covariance matrix Covs : fixed effect covariates """ vd = varianceDecomposition.VarianceDecomposition(y) if Covs is not None: vd.addFixedEffect(Covs) vd.addRandomEffect(Kbg) Klr = utils.computeLinearKernel(Z) vd.addRandomEffect(Klr) vd.addRandomEffect(is_noise=True) vd.optimize() varComps = vd.getVarianceComps()[0] Ktotal = varComps[0]*Kbg + varComps[1]*Klr lm = qtl.test_lmm(G,y,covs=Covs,K=Ktotal) pv = lm.getPv()[0] beta = lm.getBetaSNP()[0] var_snps = beta**2 * np.var(G,axis=0) var_genes = np.zeros(len(beta)) + varComps[1] var_covs = np.zeros(len(beta)) if Covs is not None: var_covs += np.dot(Covs, vd.getWeights()).var() return pv, beta, var_snps, var_covs, var_genes
def test_lmm_lr(G, y, Z, Kbg, Covs=None): """ low-rank lmm input: G : genotypes y : phenotype Z : features of low-rank matrix Kbg : background covariance matrix Covs : fixed effect covariates """ vd = varianceDecomposition.VarianceDecomposition(y) if Covs is not None: vd.addFixedEffect(Covs) vd.addRandomEffect(Kbg) Klr = utils.computeLinearKernel(Z) vd.addRandomEffect(Klr) vd.addRandomEffect(is_noise=True) vd.optimize() varComps = vd.getVarianceComps()[0] Ktotal = varComps[0] * Kbg + varComps[1] * Klr lm = qtl.test_lmm(G, y, covs=Covs, K=Ktotal) pv = lm.getPv()[0] beta = lm.getBetaSNP()[0] var_snps = beta**2 * np.var(G, axis=0) var_genes = np.zeros(len(beta)) + varComps[1] var_covs = np.zeros(len(beta)) if Covs is not None: var_covs += np.dot(Covs, vd.getWeights()).var() return pv, beta, var_snps, var_covs, var_genes
def set_K(self, K=None, X=None, U=None, S=None): """ setting background covariance matrix input: K : covariance matrix [NxN] X : genetric markers used for constructing the covariance marix [NxF]. """ N = self.genoreader.get_ncols() if K is not None: assert K.shape[0] == N assert K.shape[1] == N self.K = K if X is not None: assert X.shape[0] == N self.K = utils.computeLinearKernel(X) if (U is None) or (S is None): S, U = scipy.linalg.eigh(K) self.S = S self.U = U