Пример #1
0
 def __init__(self, z1, z2, x, w, N1, N2, M, intercept_hsq1=None, intercept_hsq2=None,
              intercept_gencov=None, n_blocks=200, slow=False, twostep=None):
     self.intercept_gencov = intercept_gencov
     self._negative_hsq = None
     n_snp, n_annot = x.shape
     hsq1 = Hsq(np.square(z1), x, w, N1, M, n_blocks=n_blocks, intercept=intercept_hsq1,
                slow=slow, twostep=twostep)
     hsq2 = Hsq(np.square(z2), x, w, N2, M, n_blocks=n_blocks, intercept=intercept_hsq2,
                slow=slow, twostep=twostep)
     gencov = Gencov(z1, z2, x, w, N1, N2, M, hsq1.tot, hsq2.tot, hsq1.intercept,
                     hsq2.intercept, n_blocks, intercept_gencov=intercept_gencov, slow=slow,
                     twostep=twostep)
     gencov.N1 = None  # save memory
     gencov.N2 = None
     self.hsq1, self.hsq2, self.gencov = hsq1, hsq2, gencov
     if (hsq1.tot <= 0 or hsq2.tot <= 0):
         self._negative_hsq = True
         self.rg_ratio = self.rg = self.rg_se = 'NA'
         self.p = self.z = 'NA'
     else:
         rg_ratio = np.array(
             gencov.tot / np.sqrt(hsq1.tot * hsq2.tot)).reshape((1, 1))
         denom_delete_values = np.sqrt(
             np.multiply(hsq1.tot_delete_values, hsq2.tot_delete_values))
         rg = jk.RatioJackknife(
             rg_ratio, gencov.tot_delete_values, denom_delete_values)
         self.rg_jknife = float(rg.jknife_est)
         self.rg_se = float(rg.jknife_se)
         self.rg_ratio = float(rg_ratio)
         self.p, self.z = p_z_norm(self.rg_ratio, self.rg_se)
Пример #2
0
    def _enrichment_g(self,
                      g_overlap_matrix,
                      coef,
                      ave_coef,
                      jknife,
                      n_annot,
                      n_g_tot_annot,
                      indices=None):
        n_blocks = jknife.delete_values.shape[0]
        delete_vals = np.dot(g_overlap_matrix,
                             jknife.delete_values[:, n_annot:self.n_annot].T).T
        if indices:
            numer_delete_vals = np.mean(delete_vals[:, indices],
                                        axis=1).reshape((n_blocks, 1))
        else:
            numer_delete_vals = delete_vals
        denom_delete_vals = np.mean(delete_vals[:, :n_g_tot_annot],
                                    axis=1).reshape((n_blocks, 1))

        if not indices:
            denom_delete_vals = np.dot(denom_delete_vals,
                                       np.ones((1, self.n_annot - n_annot)))

        prop = jk.RatioJackknife(coef / ave_coef, numer_delete_vals,
                                 denom_delete_vals)

        return prop.est, prop.jknife_cov, prop.jknife_se
Пример #3
0
 def _prop(self, jknife, M, Nbar, cat, tot):
     '''Convert total h2 and per-category h2 to per-category proportion h2 or gencov.'''
     n_annot = self.n_annot
     n_blocks = jknife.delete_values.shape[0]
     numer_delete_vals = np.multiply(
         M, jknife.delete_values[:, 0:n_annot]) / Nbar  # (n_blocks, n_annot)
     denom_delete_vals = np.sum(
         numer_delete_vals, axis=1).reshape((n_blocks, 1))
     denom_delete_vals = np.dot(denom_delete_vals, np.ones((1, n_annot)))
     prop = jk.RatioJackknife(
         cat / tot, numer_delete_vals, denom_delete_vals)
     return prop.est, prop.jknife_cov, prop.jknife_se
Пример #4
0
 def _prop(self, jknife, M, Nbar, cat, tot, use_bootstrap=False):
     '''Convert total h2 and per-category h2 to per-category proportion h2 or gencov.'''
     n_annot = self.n_annot
     n_blocks = jknife.delete_values.shape[0]
     numer_delete_vals = np.multiply(
         M, jknife.delete_values[:, 0:n_annot]) / Nbar  # (n_blocks, n_annot)
     denom_delete_vals = np.sum(
         numer_delete_vals, axis=1).reshape((n_blocks, 1))
     denom_delete_vals = np.dot(denom_delete_vals, np.ones((1, n_annot)))
     if use_bootstrap:
         bootstrap_ratios = numer_delete_vals / denom_delete_vals
         ###prop_est = np.mean(bootstrap_ratios, axis=0)
         prop_est = cat / tot
         prop_cov = np.cov(bootstrap_ratios.T, ddof=1)
         prop_se = np.sqrt(np.diag(prop_cov))
         return prop_est, prop_cov, prop_se
     else:
         prop = jk.RatioJackknife(
             cat / tot, numer_delete_vals, denom_delete_vals)
         
         return prop.est, prop.jknife_cov, prop.jknife_se