rthor._permutations
Permutation generation for RTHOR randomization tests.
| FUNCTION | DESCRIPTION |
|---|---|
generate_permutations |
Generate permutations for randomization test. |
apply_permutation |
Apply permutation to correlation matrix. |
generate_permutations
Generate permutations for randomization test.
Note
Translated from RTHORR/R/randall.R lines 92-107.
Critical for parity with RTHORR: Permutation order must match R exactly.
R uses permute::allPerms() which generates permutations in
lexicographic order. Python's itertools.permutations() also uses
lexicographic order, so they should match.
When n! > max_perm, uses random sampling instead of all permutations.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of variables to permute
TYPE:
|
max_perm
|
Maximum number of permutations to generate
TYPE:
|
seed
|
Random seed for reproducibility when using random sampling
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Permutation matrix (nper x n) where each row is a permutation. Values are 0-indexed (unlike R which is 1-indexed). |
Source code in src/rthor/_permutations.py
apply_permutation
Apply permutation to correlation matrix.
Note
Translated from RTHORR/R/randall.R lines 162-165.
R code: dmatp[i,j] <- dmat[pp[i], pp[j]]
This permutes both rows and columns simultaneously.
| PARAMETER | DESCRIPTION |
|---|---|
dmat
|
Original correlation matrix (n x n)
TYPE:
|
perm
|
Permutation vector (length n), 0-indexed
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Permuted correlation matrix (n x n) |
Source code in src/rthor/_permutations.py
:::