Given a prior matrix P (k x p) whose rows are correlated and potentially over-represent some latent signals, this function produces a reduced set of row-priors that are uncorrelated and representative.

transform_prior_rows_to_uncorrelated(
  P,
  j = NULL,
  method = c("svd", "cluster_then_svd"),
  row_center = TRUE,
  row_scale = FALSE,
  varimax = FALSE,
  cluster_k = NULL,
  var_exp_threshold = 0.9,
  verbose = TRUE
)

Arguments

P

numeric matrix (k x p) — rows are the priors to compress/orthogonalize.

j

integer or NULL. Number of components to keep. If NULL, chosen automatically.

method

character, one of "svd" or "cluster_then_svd".

row_center

logical. Subtract row means before analysis (recommended).

row_scale

logical. Scale rows to unit sd (optional).

varimax

logical. Apply varimax rotation to loadings (improves interpretability).

cluster_k

integer or NULL. If method = "cluster_then_svd", number of clusters. If NULL, chosen with silhouette / dynamic.

var_exp_threshold

numeric in (0,1). If j is NULL, choose smallest j with cumulative variance >= this threshold.

verbose

logical.

Value

A list with elements: - P_orig: original input - P_trans: transformed row-priors (j x p) (rows uncorrelated) - U: left singular vectors (k x j) - S: singular values (j) - Vt: right singular vectors transposed (j x p) - transform_fn: function(newP) to map new data with same transform - diagnostics: list with eigenvalues, variance explained, chosen j, clustering info

Details

Methods: - "svd" : row-PCA / SVD on P (default). Returns top j orthogonal components. - "cluster_then_svd": cluster correlated rows, compute cluster centroids, then run SVD on centroids to produce orthogonal representatives.

The function will: 1. optionally normalize rows 2. compute SVD of P (or of centroids) 3. select j (user provided or automatic by variance explained) 4. return j orthogonal (uncorrelated) row-vectors in R^p