cor.results: Reformatted Correlation Matrix with _p_-Values and Confidence...

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Reformat correlation matrix from cor into variable-pair format, with options to calulate statistical significance and confidence intervals and sort results by required result attribute.

Usage

1
cor.results(cormat, sort.by="r", data=NULL, var.name=NULL)

Arguments

cormat

A matrix of correlation results returned from the cor function

sort.by

Specify what order variable-pairs are reported in. Default value of “r” sorts results in descending order of correlation coefficient. Other options are to sort by absolute value of r (“abs.r”), sort by p-value (“p.value”) or sort by the names of variables in the “x” or “y” columns.

data

Default = NULL. If a data frame is supplied, then p-values and confidence intervals are calculated for each variable-pair. Note that data frame specified must be the same one used by cor to produce the correlation matrix being reformatted.

var.name

Default = NULL. If a variable name is supplied, results are reported only for variable pairs including that variable.

Value

Returns a data frame identifying the names of each variable pair, the correlation between them and, optionally, the associted p-value, significance level and confidence intervals.

Note

Borrows heavily from http://www.sthda.com/english/wiki/correlation-matrix-an-r-function-to-do-all-you-need

Author(s)

Paul Williamson

See Also

cor; cor.test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Generate correlation matrix using the function cor( )
res <- cor(survey[, 8:11]) # use continuous variables only

## convert correlation matrix into 'variable-pair' format
cor.results(res)

## Sort results as required
cor.results(res, sort.by = "abs.r") # by absolute value of r
cor.results(res, sort.by = "x") # by names of 'x' variables
cor.results(res, sort.by = "y") # by names of 'y' variables

## Calculate and report p-value, significance level and confidence intervals
cor.results(res, data = survey[, 8:11])

## Report results for variable pairs involving a specific variable
cor.results(res, var.name="Height")

## Combine elements of function as required
cor.results(res, data = survey[ , 8:11], var.name="Height", sort.by = "p.value")

DrPaulWilliamson/ENVS450 documentation built on May 9, 2019, 3:23 a.m.