extract_cc: Extracts Coefficient of congruence

View source: R/utility_functions.R

extract_ccR Documentation

Extracts Coefficient of congruence

Description

Given two vectors, generates the coefficient of congruence between them. This is equivalent to the cosine of the angle between both vectors.

Usage

extract_cc(vector1, vector2)

Arguments

vector1

First numerical vector for the calculation.

vector2

Second numerical vector for the calculation.

Details

The congurence coefficient is calculated as:

CC_{x,y} = sum(x_{i} X y_{i}) / sqrt(sum(x_{i}^2) X sum(y{i})^2)

Where x_{i} and y_{i} are the loadings of the variable i on the component or factor x and y respectively. CC is equivalent to the cosine of the angle between two vectors (the cosine similarity metric) and has a numerical range from -1 to 1. The sign of a component is arbitrary and can be flipped without affecting its interpretation. Here we consider the absolute value of CC (0 to 1). The closer the CC is to 1, the more similar the two components are.

Value

Returns the coefficent of congruence (CC) between vector1 and vector2.

Author(s)

Abel Torres Espin

References

  1. Burt C. The Factorial Study of Temperamental Traits. Br J Stat Psychol. 1948;1(3):178–203.

  2. Tucker, L. R. A method for synthesis of factor analysis studies. Personnel Research Section Report No.984. Washington D.C.: Department of the Army.; 1951.

Examples

data(mtcars)
pca_mtcars_1<-prcomp(mtcars, center = TRUE, scale = TRUE)

#Second pca with a subsetted mtcars as an example of comparing loading patterns
#from two proximal datasets
pca_mtcars_2<-prcomp(mtcars[1:20,], center = TRUE, scale = TRUE)

s.loadings_1<-stand_loadings(pca = pca_mtcars_1, pca_data = mtcars)
s.loadings_2<-stand_loadings(pca = pca_mtcars_2, pca_data = mtcars[1:20,])

extract_cc(s.loadings_1[,1], s.loadings_2[,1])


ucsf-ferguson-lab/syndRomics documentation built on June 26, 2022, 5:36 p.m.