def permute(self, permutations=<NUM_LIT>, alternative='<STR_LIT>'):
rY = self.Y.copy()<EOL>idxs = np.arange(len(rY))<EOL>counts = np.zeros((permutations, len(self.counts)))<EOL>for m in range(permutations):<EOL><INDENT>np.random.shuffle(idxs)<EOL>res = self._calc(rY[idxs, :], self.w, self.k)<EOL>counts[m] = res['<STR_LIT>']<EOL><DEDENT>self.counts_perm = counts<EOL>self.larger_perm = np.array(<EOL>[(counts[:, i] >= self.counts[i]).sum() for i in range(self.k)])<EOL>self.smaller_perm = np.array(<EOL>[(counts[:, i] <= self.counts[i]).sum() for i in range(self.k)])<EOL>self.expected_perm = counts.mean(axis=<NUM_LIT:0>)<EOL>self.alternative = alternative<EOL>alt = alternative.upper()<EOL>if alt == '<STR_LIT>':<EOL><INDENT>P = (self.larger_perm + <NUM_LIT:1>) / (permutations + <NUM_LIT:1.>)<EOL>mask = P < <NUM_LIT:0.5><EOL>self.p = mask * <NUM_LIT:2> * P + (<NUM_LIT:1> - mask) * <NUM_LIT:2> * (<NUM_LIT:1> - P)<EOL><DEDENT>elif alt == '<STR_LIT>':<EOL><INDENT>POS = _POS8<EOL>if self.k == <NUM_LIT:4>:<EOL><INDENT>POS = _POS4<EOL><DEDENT>L = (self.larger_perm + <NUM_LIT:1>) / (permutations + <NUM_LIT:1.>)<EOL>S = (self.smaller_perm + <NUM_LIT:1>) / (permutations + <NUM_LIT:1.>)<EOL>P = POS * L + (<NUM_LIT:1> - POS) * S<EOL>self.p = P<EOL><DEDENT>elif alt == '<STR_LIT>':<EOL><INDENT>NEG = _NEG8<EOL>if self.k == <NUM_LIT:4>:<EOL><INDENT>NEG = _NEG4<EOL><DEDENT>L = (self.larger_perm + <NUM_LIT:1>) / (permutations + <NUM_LIT:1.>)<EOL>S = (self.smaller_perm + <NUM_LIT:1>) / (permutations + <NUM_LIT:1.>)<EOL>P = NEG * L + (<NUM_LIT:1> - NEG) * S<EOL>self.p = P<EOL><DEDENT>else:<EOL><INDENT>print(('<STR_LIT>' % alternative))<EOL><DEDENT>
Generate ransom spatial permutations for inference on LISA vectors.

Parameters
----------
permutations : int, optional
    Number of random permutations of observations.
alternative : string, optional
    Type of alternative to form in generating p-values.
    Options are: `two-sided` which tests for difference between observed
    counts and those obtained from the permutation distribution;
    `positive` which tests the alternative that the focal unit and its
    lag move in the same direction over time; `negative` which tests
    that the focal unit and its lag move in opposite directions over
    the interval.