corbetw2mat: Calculate correlations between columns of two matrices

View source: R/corbetw2mat.R

corbetw2matR Documentation

Calculate correlations between columns of two matrices

Description

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

Usage

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

Arguments

x

A numeric matrix.

y

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

what

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

corthresh

Threshold on correlations if what="bestpairs".

Details

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

Value

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.

Author(s)

Karl W Broman, broman@wisc.edu

See Also

distee(), findCommonID()

Examples


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.