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(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))
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.) 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. - stats.norm.cdf(np.abs(self.z_sim))
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))
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))