corbetw2mat: Calculate correlations between columns of two matrices

View source: R/corbetw2mat.R

corbetw2matR Documentation

Calculate correlations between columns of two matrices


For matrices x and y, calculate the correlation between columns of x and columns of y.


  what = c("paired", "bestright", "bestpairs", "all"),
  corthresh = 0.9



A numeric matrix.


A numeric matrix with the same number of rows as x.


Indicates which correlations to calculate and return. See value, below.


Threshold on correlations if what="bestpairs".


Missing values (NA) are ignored, and we calculate the correlation using all complete pairs, as in stats::cor() with use="pairwise.complete.obs".


If what="paired", the return value is a vector of correlations, between columns of x and the corresponding column of y. x and y must have the same number of columns.

If what="bestright", we return a data frame of size ncol(x) by 3, with the ith row being the maximum correlation between column i of x and a column of y, and then the y-column index and y-column name with that correlation. (In case of ties, we give the first one.)

If what="bestpairs", we return a data frame with five columns, containing all pairs of columns (with one in x and one in y) with correlation corthresh. Each row corresponds to a column pair, and contains the correlation and then the x- and y-column indices followed by the x- and y-column names.

If what="all", the output is a matrix of size ncol(x) by ncol(y), with all correlations between columns of x and columns of y.


Karl W Broman,

See Also

distee(), findCommonID()


data(expr1, expr2)

# correlations with paired columns
r <- corbetw2mat(expr1, expr2)
# top 10, by absolute value
r[order(abs(r), decreasing=TRUE)[1:10]]

# all pairs of columns with correlation >= 0.8
r_allpairs <- corbetw2mat(expr1, expr2, what="bestpairs", corthresh=0.6)

# for each column in left matrix, most-correlated column in right matrix
r_bestright <- corbetw2mat(expr1, expr2, what="bestright")

lineup documentation built on July 10, 2022, 5:05 p.m.