rthor._core
Core RTHOR algorithm functions.
| FUNCTION | DESCRIPTION |
|---|---|
generate_hypothesis |
Generate hypothesis matrix for RTHOR analysis. |
calculate_fit |
Calculate fit of correlation matrix to hypothesis. |
calculate_ci |
Calculate Correspondence Index. |
run_permutation_test |
Run randomization test via permutations. |
test_single_matrix |
Test a single correlation matrix. |
test_multiple_matrices |
Test multiple correlation matrices. |
compare_two_matrices |
Compare two correlation matrices. |
compare_multiple_matrices |
Compare all pairs of correlation matrices. |
generate_hypothesis
generate_hypothesis(order: str | list[int] | ndarray, n_variables: int) -> tuple[np.ndarray, np.ndarray, int]
Generate hypothesis matrix for RTHOR analysis.
| PARAMETER | DESCRIPTION |
|---|---|
order
|
Order specification (validated by caller) |
n_variables
|
Number of variables
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
hypothesis_matrix
|
Hypothesis matrix (n_pairs x n_pairs)
TYPE:
|
order_array
|
Processed order array
TYPE:
|
n_predictions
|
Number of hypothesized predictions (count of 1s)
TYPE:
|
Source code in src/rthor/_core.py
calculate_fit
Calculate fit of correlation matrix to hypothesis.
| PARAMETER | DESCRIPTION |
|---|---|
correlation_matrix
|
Correlation matrix (n x n)
TYPE:
|
hypothesis_matrix
|
Hypothesis matrix (n_pairs x n_pairs)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
n_agreements
|
Number of predictions satisfied
TYPE:
|
n_ties
|
Number of tied correlations
TYPE:
|
Source code in src/rthor/_core.py
calculate_ci
Calculate Correspondence Index.
| PARAMETER | DESCRIPTION |
|---|---|
n_agreements
|
Number of agreements
TYPE:
|
n_ties
|
Number of ties
TYPE:
|
n_predictions
|
Number of predictions
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ci
|
Correspondence Index
TYPE:
|
Source code in src/rthor/_core.py
run_permutation_test
run_permutation_test(correlation_matrix: ndarray, hypothesis_matrix: ndarray, n_agreements: int, permutations: ndarray) -> float
Run randomization test via permutations.
| PARAMETER | DESCRIPTION |
|---|---|
correlation_matrix
|
Original correlation matrix
TYPE:
|
hypothesis_matrix
|
Hypothesis matrix
TYPE:
|
n_agreements
|
Observed number of agreements
TYPE:
|
permutations
|
Permutation matrix (n_permutations x n_variables)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
p_value
|
Proportion of permutations with fit >= observed
TYPE:
|
Source code in src/rthor/_core.py
test_single_matrix
test_single_matrix(correlation_matrix: ndarray, hypothesis_matrix: ndarray, n_predictions: int, permutations: ndarray, matrix_id: int, label: str) -> dict
Test a single correlation matrix.
| PARAMETER | DESCRIPTION |
|---|---|
correlation_matrix
|
Correlation matrix to test
TYPE:
|
hypothesis_matrix
|
Hypothesis matrix
TYPE:
|
n_predictions
|
Number of hypothesized predictions
TYPE:
|
permutations
|
Permutation matrix
TYPE:
|
matrix_id
|
Matrix identifier (1-indexed)
TYPE:
|
label
|
Matrix label
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary with keys: matrix, predictions, agreements, ties, ci, p_value, label |
Source code in src/rthor/_core.py
test_multiple_matrices
test_multiple_matrices(correlation_matrices: ndarray, order: str | list[int] | ndarray, labels: list[str] | None) -> pd.DataFrame
Test multiple correlation matrices.
| PARAMETER | DESCRIPTION |
|---|---|
correlation_matrices
|
3D array (n_variables, n_variables, n_matrices)
TYPE:
|
order
|
Hypothesized ordering |
labels
|
Matrix labels |
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Results table |
Source code in src/rthor/_core.py
compare_two_matrices
compare_two_matrices(corr_mat1: ndarray, corr_mat2: ndarray, hypothesis_matrix: ndarray, permutations: ndarray, matrix1_id: int, matrix2_id: int) -> dict
Compare two correlation matrices.
Notes
Vectorized version of R code (randmf.R:244-254).
| PARAMETER | DESCRIPTION |
|---|---|
corr_mat1
|
First correlation matrix
TYPE:
|
corr_mat2
|
Second correlation matrix
TYPE:
|
hypothesis_matrix
|
Hypothesis matrix
TYPE:
|
permutations
|
Permutation matrix
TYPE:
|
matrix1_id
|
First matrix ID
TYPE:
|
matrix2_id
|
Second matrix ID
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Comparison result with keys: |
Source code in src/rthor/_core.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
compare_multiple_matrices
compare_multiple_matrices(correlation_matrices: ndarray, order: str | list[int] | ndarray) -> tuple[pd.DataFrame, pd.DataFrame]
Compare all pairs of correlation matrices.
| PARAMETER | DESCRIPTION |
|---|---|
correlation_matrices
|
3D array (n_variables, n_variables, n_matrices)
TYPE:
|
order
|
Hypothesized ordering |
| RETURNS | DESCRIPTION |
|---|---|
rthor_df
|
Individual matrix test results
TYPE:
|
comparisons
|
Pairwise comparison results
TYPE:
|
Source code in src/rthor/_core.py
:::