Compute correlation between different types of data, reorder the variables via corrMatOrder and calculate p-values to check for significant correlations.

correlationAnalysis(
  dataset = cs.in.dataset(),
  preds = cs.in.predictors(),
  resps = cs.in.responses(),
  scriptvars = cs.in.scriptvars(),
  return.results = FALSE
)

Arguments

dataset

[data.frame]
Dataset with named columns. The names correspond to predictors and responses.

preds

[character]
Character vector of predictor variables.

resps

[character]
Character vector of response variables.

scriptvars

[list]
Named list of script variables set via the Cornerstone "Script Variables" menu. For details see below.

return.results

[logical(1)]
If FALSE the function returns TRUE invisibly. If TRUE, it returns a list of results. Default is FALSE.

Value

Logical [TRUE] invisibly and outputs to Cornerstone or, if return.results = TRUE, list of resulting data.table objects:

corMatrix

Represent all correlations in an X vs. X or X vs. Y matrix form. If ordering is selected, the matrix will be sorted if symmetrical.

corTable

Represent all correlations, confidence intervals and p-values pairwise including their positions to create a Tilemap graph in Cornerstone.

Details

To reorder the data, it is necessary to put all variables in predictors and leave responses blank to obtain a symmetrical matrix. To calculate the correlation between different types, put categorical data in predictors and numerical in responses.
The following script variables are summarized in scriptvars list:

methodNum

[character(1)]
The preferred method to compute correlation between numerical variables. Select from Pearson and Spearman. Default is Pearson.

order

[character(1)]
The type of ordering for symmetrical matrices to select from:
AOE: angular order of eigenvectors.
FPC: first principle component.
original: original order of given dataset.
alphabet: alphabetical order.
Default is FPC.

conf.level

[character(1)]
The Confidence Level (1 - Significance Level (alpha error)) to determine significant correlations. It can be set to 0.90, 0.95, 0.975 or 0.99. Default is 0.90.

re.insig

[logical(1)]
If TRUE, insignificant correlations based on the chosen confidence level will be set to NA. Default is FALSE.

See also

cor.test for calculation between numerical variables
chisq.test for calculation of Cramer's V for correlation between categorical variables
boot.ci for bootstrap calculation of Cramer's V confidence interval
lm for calculation of adjusted R-squared for correlation between numerical and categorical variables.

Examples

# compute correlation between numerical variables in mtcars data
correlationAnalysis(mtcars,
  preds = names(mtcars)[1:5],
  resps = names(mtcars)[6:10],
  scriptvars = list(
    methodNum = "Pearson", order = "FPC",
    conf.level = "0.95", rm.insig = TRUE
  ),
  return.results = TRUE
)
#> $table
#>    Variable1 Variable2 Correlation      p.Value    Lower_CI   Upper_CI x  y
#> 1         wt       mpg     -0.8677 1.293959e-10 -0.93382641 -0.7440872 5  0
#> 2       qsec       mpg      0.4187 1.708199e-02  0.08195487  0.6696186 3  2
#> 3         vs       mpg      0.6640 3.415937e-05  0.41036301  0.8223262 4  1
#> 4         am       mpg      0.5998 2.850207e-04  0.31755830  0.7844520 1  4
#> 5       gear       mpg      0.4803 5.400948e-03  0.15806177  0.7100628 2  3
#> 6         wt       cyl      0.7825 1.217567e-07  0.59657947  0.8887052 5 -4
#> 7       qsec       cyl     -0.5912 3.660533e-04 -0.77927809 -0.3055388 3 -2
#> 8         vs       cyl     -0.8108 1.843018e-08 -0.90393935 -0.6442689 4 -3
#> 9         am       cyl     -0.5226 2.151207e-03 -0.73699794 -0.2126675 1  0
#> 10      gear       cyl     -0.4927 4.173297e-03 -0.71802597 -0.1738615 2 -1
#> 11        wt      disp      0.8880 1.222320e-11  0.78115863  0.9442902 5 -3
#> 12      qsec      disp     -0.4337 1.314404e-02 -0.67961513 -0.1001493 3 -1
#> 13        vs      disp     -0.7104 5.235012e-06 -0.84883771 -0.4808327 4 -2
#> 14        am      disp     -0.5912 3.662114e-04 -0.77926901 -0.3055178 1  1
#> 15      gear      disp     -0.5556 9.635921e-04 -0.75751468 -0.2565810 2  0
#> 16        wt        hp      0.6587 4.145827e-05  0.40251134  0.8192573 5 -1
#> 17      qsec        hp     -0.7082 5.766253e-06 -0.84759984 -0.4774331 3  1
#> 18        vs        hp     -0.7231 2.940896e-06 -0.85596751 -0.5006318 4  0
#> 19        am        hp          NA 1.798309e-01          NA         NA 1  3
#> 20      gear        hp          NA 4.930119e-01          NA         NA 2  2
#> 21        wt      drat     -0.7124 4.784260e-06 -0.84997951 -0.4839784 5 -2
#> 22      qsec      drat          NA 6.195826e-01          NA         NA 3  0
#> 23        vs      drat      0.4403 1.167553e-02  0.10819483  0.6839680 4 -1
#> 24        am      drat      0.7127 4.726790e-06  0.48439908  0.8501319 1  2
#> 25      gear      drat      0.6996 8.360110e-06  0.46414402  0.8427222 2  1
#>    width height
#> 1    0.8    0.8
#> 2    0.8    0.8
#> 3    0.8    0.8
#> 4    0.8    0.8
#> 5    0.8    0.8
#> 6    0.8    0.8
#> 7    0.8    0.8
#> 8    0.8    0.8
#> 9    0.8    0.8
#> 10   0.8    0.8
#> 11   0.8    0.8
#> 12   0.8    0.8
#> 13   0.8    0.8
#> 14   0.8    0.8
#> 15   0.8    0.8
#> 16   0.8    0.8
#> 17   0.8    0.8
#> 18   0.8    0.8
#> 19   0.8    0.8
#> 20   0.8    0.8
#> 21   0.8    0.8
#> 22   0.8    0.8
#> 23   0.8    0.8
#> 24   0.8    0.8
#> 25   0.8    0.8
#> 
#> $matrix
#>      name     mpg     cyl    disp      hp    drat
#> wt     wt -0.8677  0.7825  0.8880  0.6587 -0.7124
#> qsec qsec  0.4187 -0.5912 -0.4337 -0.7082      NA
#> vs     vs  0.6640 -0.8108 -0.7104 -0.7231  0.4403
#> am     am  0.5998 -0.5226 -0.5912      NA  0.7127
#> gear gear  0.4803 -0.4927 -0.5556      NA  0.6996
#>