Compute Second-Order Similarity Scores
second_order_similarity.Rd
This function calculates the second order similarity between two similarity vectors derived from a provided distance function applied to matrix X and a reference similarity matrix S. The calculation takes into account a blocking variable to exclude comparisons within the same block.
Usage
second_order_similarity(
dist_fun,
X,
D,
block,
method = c("pearson", "spearman")
)
Arguments
- dist_fun
A distance function object or a character string specifying the method used for distance computation. This function should be capable of processing the matrix X to produce a distance matrix.
- X
A numeric matrix where each row is an observation and columns are features. Distances will be computed pairwise between rows of this matrix.
- D
A numeric matrix, typically a predefined dissimilarity matrix that serves as a reference to compare against the computed distances from X.
- block
A vector (numeric or factor) indicating the block or group for each row in X and S. Comparisons are only made between elements of different blocks.
- method
The method used for computing correlation between similarity vectors. Defaults to "pearson", but "spearman" or "kendall" could also be used.
Value
A numeric vector of similarity scores, one for each observation in X, representing the correlation between distance vectors derived from X and the corresponding vectors in S for non-matching blocks.
Details
The function computes a distance matrix for X using the specified `dist_fun`. It then compares these distances with the entries in S for each observation, excluding comparisons within the same block as defined by the `block` argument. This is useful for evaluating how well the distances within X align with an external similarity standard, adjusting for within-block dependencies.
Examples
# Assuming X and S are numeric matrices and block is a factor or numeric vector
dist_fun <- "euclidean" # This should be defined or loaded from your package/environment
X <- matrix(rnorm(100), ncol=10)
D <- matrix(rnorm(100), ncol=10)
block <- rep(1:5, each=20)
scores <- second_order_similarity(dist_fun, X, D, block, method = "pearson")
#> Error in pairwise_dist.default(dist_fun, X): pairwise_dist not implemented for objects of class matrix