View source: R/vector_rsa_model.R
second_order_similarity | R Documentation |
Calculates correlation-based second order similarity between:
A full NxN distance matrix computed from X
via distfun
, and
A Dref
matrix (the "reference" dissimilarities).
For each row i
, this excludes same-block comparisons by selecting which(block_var != block_var[i])
.
second_order_similarity(
distfun,
X,
Dref,
block_var,
method = c("pearson", "spearman")
)
distfun |
An S3 distance object (see |
X |
A numeric matrix (rows = observations, columns = features). |
Dref |
A numeric NxN reference matrix of dissimilarities (e.g., from an ROI mask or a prior). |
block_var |
A vector indicating block/group memberships for each row in |
method |
Correlation method: "pearson" or "spearman". |
This function first calls pairwise_dist(distfun, X)
, obtaining an NxN matrix
of all pairwise distances. It does not do block-based exclusion internally.
Instead, for each row i
, it excludes same-block rows from the correlation
by subsetting the distances to valid_indices
.
A numeric vector of length nrow(X)
, where each entry is
the correlation (using method
) between distance_matrix[i, valid]
and
Dref[i, valid]
, with valid = which(block_var != block_var[i])
.
# Suppose we have X (10x5), a reference D (10x10), block var, and a correlation distfun:
X <- matrix(rnorm(50), 10, 5)
D <- matrix(runif(100), 10, 10)
block <- rep(1:2, each=5)
dist_obj <- cordist(method="pearson")
scores <- second_order_similarity(dist_obj, X, D, block, method="spearman")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.