Compares correspondence between two result matrices (e.g., factor loadings) across multiple targets using correlation, AUC, or t-statistics. Produces a paired comparison plot and summary statistics.
compareBs(
res1,
res2,
target,
method = "p",
xlab = "1",
ylab = "2",
stat.method = "t",
oneToOne = TRUE
)res2 Result objects or matrices containing factor loadings.
If a list, must contain element B; if of class "rsvd",
t(res$v) is used.
Second result object or matrix to compare against.
Numeric matrix of target variables (samples × targets).
Character, one of "p", "s", "a", or "t", indicating
Pearson, Spearman, AUC, or t-statistic comparison.
ylab Labels for x and y axes in the plot.
Label for y-axis (used in plot).
Statistical test to compare correlations
("t" or "wilcox").
Logical, whether to apply one-to-one masking of associations.
A list with:
A ggplot object comparing maximal correlations across targets.
A data.frame with per-target metrics and (if available) top genes.
set.seed(123)
# Simulated example with 50 genes × 20 samples
Y <- matrix(rnorm(50 * 20), nrow = 50, ncol = 20)
# Run two CLAMP-like decompositions (here using simple SVD)
svd1 <- rsvd::rsvd(Y, k = 5)
svd2 <- rsvd::rsvd(Y + matrix(rnorm(50 * 20, 0, 0.1), 50, 20), k = 5)
# Define a target variable (e.g., binary or continuous trait)
target <- matrix(rnorm(20 * 3), ncol = 3)
colnames(target) <- c("Trait1", "Trait2", "Trait3")
# Compare the two sets of embeddings
res <- compareBs(svd1, svd2, target,
method = "p", xlab = "SVD1", ylab = "SVD2"
)
#> [1] 5 20
#> [1] 5 20