Beispiel #1
0
 def __init__(
     self,
     y,
     w,
     transform="R",
     permutations=PERMUTATIONS,
     star=False,
     keep_simulations=True,
 ):
     y = np.asarray(y).flatten()
     self.n = len(y)
     self.y = y
     self.w = w
     self.w_original = w.transform
     self.w.transform = self.w_transform = transform.lower()
     self.permutations = permutations
     self.star = star
     self.calc()
     self.p_norm = np.array([1 - stats.norm.cdf(np.abs(i)) for i in self.Zs])
     if permutations:
         self.__crand(keep_simulations)
         if keep_simulations:
             self.sim = sim = self.rGs.T
             self.EG_sim = sim.mean(axis=0)
             self.seG_sim = sim.std(axis=0)
             self.VG_sim = self.seG_sim * self.seG_sim
             self.z_sim = (self.Gs - self.EG_sim) / self.seG_sim
             self.p_z_sim = 1 - stats.norm.cdf(np.abs(self.z_sim))
Beispiel #2
0
    def __init__(self, y, w, permutations=PERMUTATIONS):
        y = np.asarray(y).flatten()
        self.n = len(y)
        self.y = y
        w.transform = "B"
        self.w = w
        self.permutations = permutations
        self.__moments()
        self.y2 = y * y
        y = y.reshape(
            len(y), 1
        )  # Ensure that y is an n by 1 vector, otherwise y*y.T == y*y
        self.den_sum = (y * y.T).sum() - (y * y).sum()
        self.G = self.__calc(self.y)
        self.z_norm = (self.G - self.EG) / np.sqrt(self.VG)
        self.p_norm = 1.0 - stats.norm.cdf(np.abs(self.z_norm))

        if permutations:
            sim = [
                self.__calc(np.random.permutation(self.y)) for i in range(permutations)
            ]
            self.sim = sim = np.array(sim)
            above = sim >= self.G
            larger = sum(above)
            if (self.permutations - larger) < larger:
                larger = self.permutations - larger
            self.p_sim = (larger + 1.0) / (permutations + 1.0)
            self.EG_sim = sum(sim) / permutations
            self.seG_sim = sim.std()
            self.VG_sim = self.seG_sim ** 2
            self.z_sim = (self.G - self.EG_sim) / self.seG_sim
            self.p_z_sim = 1.0 - stats.norm.cdf(np.abs(self.z_sim))
Beispiel #3
0
 def __init__(self,
              y,
              w,
              transform='R',
              permutations=PERMUTATIONS,
              star=False):
     y = np.asarray(y).flatten()
     self.n = len(y)
     self.y = y
     self.w = w
     self.w_original = w.transform
     self.w.transform = self.w_transform = transform.lower()
     self.permutations = permutations
     self.star = star
     self.calc()
     self.p_norm = np.array(
         [1 - stats.norm.cdf(np.abs(i)) for i in self.Zs])
     if permutations:
         self.__crand()
         sim = np.transpose(self.rGs)
         above = sim >= self.Gs
         larger = sum(above)
         low_extreme = (self.permutations - larger) < larger
         larger[low_extreme] = self.permutations - larger[low_extreme]
         self.p_sim = (larger + 1.0) / (permutations + 1)
         self.sim = sim
         self.EG_sim = sim.mean()
         self.seG_sim = sim.std()
         self.VG_sim = self.seG_sim * self.seG_sim
         self.z_sim = (self.Gs - self.EG_sim) / self.seG_sim
         self.p_z_sim = 1 - stats.norm.cdf(np.abs(self.z_sim))
Beispiel #4
0
 def __init__(
     self,
     y,
     w,
     transform="R",
     permutations=PERMUTATIONS,
     star=False,
     keep_simulations=True,
     n_jobs=-1,
     seed=None,
     island_weight=0,
 ):
     y = np.asarray(y).flatten()
     self.n = len(y)
     self.y = y
     w, star = _infer_star_and_structure_w(w, star, transform)
     w.transform = transform
     self.w_transform = transform
     self.w = w
     self.permutations = permutations
     self.star = star
     self.calc()
     self.p_norm = 1 - stats.norm.cdf(np.abs(self.Zs))
     if permutations:
         self.p_sim, self.rGs = _crand_plus(
             y,
             w,
             self.Gs,
             permutations,
             keep_simulations,
             n_jobs=n_jobs,
             stat_func=_g_local_star_crand if star else _g_local_crand,
             scaling=y.sum(),
             seed=seed,
             island_weight=island_weight,
         )
         if keep_simulations:
             self.sim = sim = self.rGs.T
             self.EG_sim = sim.mean(axis=0)
             self.seG_sim = sim.std(axis=0)
             self.VG_sim = self.seG_sim * self.seG_sim
             self.z_sim = (self.Gs - self.EG_sim) / self.seG_sim
             self.p_z_sim = 1 - stats.norm.cdf(np.abs(self.z_sim))