def __init__(self, y, regime, permutations=999): ranks = rankdata(y, axis=0) self.ranks = ranks n, k = y.shape ranks_d = ranks[:, list(range(1, k))] - ranks[:, list(range(k - 1))] self.ranks_d = ranks_d regimes = sp.unique(regime) self.regimes = regimes self.total = sum(abs(ranks_d)) self.max_total = sum([abs(i - n + i - 1) for i in range(1, n + 1)]) self._calc(regime) self.theta = self._calc(regime) self.permutations = permutations if permutations: np.perm = np.random.permutation sim = np.array([self._calc(np.perm(regime)) for i in range(permutations)]) self.theta.shape = (1, len(self.theta)) sim = np.concatenate((self.theta, sim)) self.sim = sim den = permutations + 1.0 self.pvalue_left = (sim <= sim[0]).sum(axis=0) / den self.pvalue_right = (sim > sim[0]).sum(axis=0) / den self.z = (sim[0] - sim.mean(axis=0)) / sim.std(axis=0)
def __init__(self, y, regime, permutations=999): ranks = rankdata(y, axis=0) self.ranks = ranks n, k = y.shape ranks_d = ranks[:, range(1, k)] - ranks[:, range(k - 1)] self.ranks_d = ranks_d regimes = sp.unique(regime) self.regimes = regimes self.total = sum(abs(ranks_d)) self.max_total = sum([abs(i - n + i - 1) for i in range(1, n + 1)]) self._calc(regime) self.theta = self._calc(regime) self.permutations = permutations if permutations: np.perm = np.random.permutation sim = np.array([self._calc( np.perm(regime)) for i in xrange(permutations)]) self.theta.shape = (1, len(self.theta)) sim = np.concatenate((self.theta, sim)) self.sim = sim den = permutations + 1. self.pvalue_left = (sim <= sim[0]).sum(axis=0) / den self.pvalue_right = (sim > sim[0]).sum(axis=0) / den self.z = (sim[0] - sim.mean(axis=0)) / sim.std(axis=0)