corrarray: Correlation Arrays and 2-Sample Correlation Matrices

Description Usage Arguments Details Value See Also Examples

View source: R/corrarray.R

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

1
2
3
4
5
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

1
2
3
4
5
6
7
8
## 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")

corrarray documentation built on Aug. 26, 2020, 9:06 a.m.