rthor._input
Input processing for RTHOR analyses.
| FUNCTION | DESCRIPTION |
|---|---|
process_input |
Process various input formats into 3D correlation matrix array. |
read_correlation_matrices |
Read correlation matrices from text file. |
extract_lower_triangle |
Extract lower triangular values from correlation matrix. |
process_input
process_input(data: Path | str | list[DataFrame] | ndarray, n_matrices: int | None = None, n_variables: int | None = None) -> tuple[np.ndarray, int, int]
Process various input formats into 3D correlation matrix array.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Input data in various formats:
|
n_matrices
|
Number of matrices (required for file input if ambiguous)
TYPE:
|
n_variables
|
Number of variables (required for file input if ambiguous)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
correlation_matrices
|
3D array of shape (n_variables, n_variables, n_matrices)
TYPE:
|
n_variables
|
Number of variables
TYPE:
|
n_matrices
|
Number of matrices
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If input format is invalid or parameters are missing |
Source code in src/rthor/_input.py
_process_file_input
_process_file_input(filepath: Path | str, n_matrices: int | None, n_variables: int | None) -> tuple[np.ndarray, int, int]
Process file input.
Source code in src/rthor/_input.py
_process_dataframe_list
Process list of DataFrames.
Source code in src/rthor/_input.py
_process_array_input
Process numpy array input.
Source code in src/rthor/_input.py
_build_3d_from_vector
Build 3D correlation matrix array from flat vector.
Matches logic from io.py read_correlation_matrices().
| PARAMETER | DESCRIPTION |
|---|---|
za
|
Flat array of correlation values
TYPE:
|
n_variables
|
Number of variables
TYPE:
|
n_matrices
|
Number of matrices
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
3D array (n_variables, n_variables, n_matrices) |
Source code in src/rthor/_input.py
read_correlation_matrices
Read correlation matrices from text file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to input file containing correlation matrices |
n
|
Number of variables (matrix dimension)
TYPE:
|
nmat
|
Number of matrices in the file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
3D array of correlation matrices (n x n x nmat) |
Notes
Translated from RTHORR/R/randall.R
lines 49-67.
Input file format:
- Lower triangular matrices including diagonal
- Values separated by whitespace
- Each matrix starts with diagonal element (1.00)
-
Example for n=3:
1.00 .62 1.00 .40 .62 1.00
The R code reads this using scan() and fills the matrix in two passes:
- Upper triangle (i <= j)
- Lower triangle (i >= j)
This creates a symmetric matrix.
Source code in src/rthor/_input.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 | |
extract_lower_triangle
Extract lower triangular values from correlation matrix.
| PARAMETER | DESCRIPTION |
|---|---|
corr_matrix
|
Correlation matrix (n x n)
TYPE:
|
include_diagonal
|
Whether to include diagonal values
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Lower triangular values in row-major order |
Notes
Used by rthor.test and
rthor.compare via
process_input
to convert correlation matrices computed from DataFrames into the
format expected by the file reading functions.
Matches R's gdata::lowerTriangle(cor_df, diag=TRUE, byrow=TRUE)
Source code in src/rthor/_input.py
:::