Package 'corrarray'

Title: Correlation Arrays and 2-Sample Correlation Matrices
Description: The goal of 'corrarray' is to create a multi-sample correlation array by combining the correlation matrices of a data set stratified by a grouping variable. For two specified levels of the variable, 'corrarray' displays one level's correlation matrix in the lower triangular matrix and the other level's correlation matrix in the upper triangular matrix. Such an output can enable visualization of correlations from two samples in a single correlation matrix or corrgram.
Authors: Rohan Reddy Tummala
Maintainer: Rohan Reddy Tummala <[email protected]>
License: GPL-3
Version: 1.2.0
Built: 2025-03-01 03:04:54 UTC
Source: https://github.com/medicine1/corrarray

Help Index


Correlation Arrays and 2-Sample Correlation Matrices

Description

This function creates a multi-sample correlation array combining the correlation matrices for each level of the specified grouping variable. Given two levels of the grouping variable, this function creates a single correlation matrix displaying the individual triangular matrices on opposite sides of the principal diagonal.

Usage

corrarray(x, group = NULL, lower = NULL, upper = NULL,
  output = c("matrix", "array", "sig.matrix", "sig.array"),
  use = c("complete.obs", "everything", "all.obs",
  "na.or.complete", "pairwise.complete.obs"),
  method = c("pearson", "kendall", "spearman"))

Arguments

x

a matrix or data frame. Variables can be quantitative or categorical.

group

the grouping variable name. If no group is specified (default), then a single correlation matrix for the entire sample will be generated.

lower

the level of the grouping variable to be placed in the lower triangular matrix. If no level is specified (default), then the first level in the data set is treated as the lower level.

upper

the level of the grouping variable to be placed in the upper triangular matrix. If no level is specified (default), then the second level in the data set is treated as the lower level.

output

If a group that has 2 or more levels is specified, then "matrix" (default) returns the corresponding 2-sample correlation matrix, and "array" returns the correlation array. "sig.matrix" and "sig.array" return the significance values of the corresponding correlations.

use

an optional character string giving a method for computing correlations in the presence of missing values. This must be one of the strings "complete.obs" (default), "everything", "all.obs", "na.or.complete", or "pairwise.complete.obs". The default option removes rows with missing values from calculations.

method

a character string indicating which correlation coefficient is to be computed: "pearson" (default), "kendall", or "spearman".

Details

If multiple values are provided for group, lower, or upper, then only the first value is used. Apart from the grouping variable, all other variables whose values are not numeric are removed from the correlation matrices. The grouping variable's values, even if numeric, are automatically treated as different levels.

Value

corrarray returns an array or matrix of correlations as numeric values from -1 to 1 (inclusive), or of significance values of the corresponding correlations, and with row and column names as the variable names.

See Also

cor for further descriptions of the use and method parameters, and rcorr for significance tests of correlations.

Examples

## All observations: 1-sample correlation matrix.
corrarray(iris)

## Stratify by the three species: 3-sample correlation array.
corrarray(iris, "Species", output = "array")

## Specify lower and upper samples: 2-sample correlation matrix.
corrarray(iris, "Species", lower = "setosa", upper = "virginica")