corrarray {corrarray} | R Documentation |
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 " |
use |
an optional character string giving a method for
computing correlations in the presence of missing values.
This must be one of the strings " |
method |
a character string indicating which correlation coefficient
is to be computed: " |
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")