Correlation

correlation(x, y, ...)

# S4 method for numeric,numeric
correlation(x, y, method = c("pearson", "kendall", "spearman"))

# S4 method for matrix,missingOrNULL
correlation(x, y = NULL, method = c("pearson", "kendall", "spearman"))

# S4 method for matrix,matrix
correlation(x, y, method = c("pearson", "kendall", "spearman"))

# S4 method for Matrix,missingOrNULL
correlation(x, y = NULL, method = c("pearson", "kendall", "spearman"))

# S4 method for Matrix,Matrix
correlation(x, y, method = c("pearson", "kendall", "spearman"))

# S4 method for SummarizedExperiment,missingOrNULL
correlation(
  x,
  y = NULL,
  i = 1L,
  j = NULL,
  method = c("pearson", "kendall", "spearman")
)

# S4 method for SummarizedExperiment,SummarizedExperiment
correlation(x, y, i = 1L, method = c("pearson", "kendall", "spearman"))

Arguments

x

Object.

y

Object.

method

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

i

integer(1) or character(1). For SummarizedExperiment, primary assay.

j

integer(1), character(1), or NULL. For SummarizedExperiment, optional secondary assay. If NULL, calculates correlation matrix only on the primary assay.

...

Additional arguments.

Value

numeric(1) or matrix.

Note

Updated 2019-11-08.

See also

Examples

data(correlation, package = "acidtest") list <- correlation rm(correlation)
#> Warning: object 'correlation' not found
## vector ==== x <- list[["vector_x"]] y <- list[["vector_y"]] head(x)
#> [1] 1 5 4 2 0 2
head(y)
#> [1] 1.6343433 3.6762875 4.7308222 0.5660087 -0.8572071 3.5346193
correlation(x = x, y = y)
#> Calculating pearson correlation on 100 values.
#> [1] 0.9634786
## matrix ==== x <- list[["matrix_x"]] y <- list[["matrix_y"]] head(x)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 1 1 1 0 7 1 3 11 3 10 #> [2,] 5 8 5 2 11 20 3 0 11 0 #> [3,] 4 11 2 0 5 0 6 0 2 7 #> [4,] 2 6 7 12 4 8 0 1 2 8 #> [5,] 0 3 2 4 3 2 0 5 2 1 #> [6,] 2 6 0 4 11 1 0 0 2 0
head(y)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] #> [1,] 1.6343433 -0.5999092 1.8159738 1.1496279 7.170519 1.561246 2.8229171 #> [2,] 3.6762875 8.7288806 3.4820749 1.4867973 11.290924 18.468396 4.9713020 #> [3,] 4.7308222 11.8516005 1.9901926 -0.5939147 6.326446 1.852269 5.9681443 #> [4,] 0.5660087 4.7761165 5.1564128 12.2934493 4.591485 7.871963 0.7907310 #> [5,] -0.8572071 3.0976105 3.3745135 4.4976942 1.294703 2.176753 -0.3036267 #> [6,] 3.5346193 7.8470870 -0.5275027 5.3964767 10.936949 2.177984 0.8971997 #> [,8] [,9] [,10] #> [1,] 9.6431737 3.811118 11.0378596 #> [2,] -0.1783549 9.242401 -1.5963026 #> [3,] 1.1793192 2.091185 7.2866099 #> [4,] 2.5901375 1.540074 7.1869350 #> [5,] 4.5118578 3.426261 -0.6193615 #> [6,] -1.7009159 1.383546 -1.7171582
stats::cor(x)
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 1.0000000 0.11769600 0.40067107 -0.19869260 0.432248547 0.205519098 #> [2,] 0.1176960 1.00000000 -0.09731989 -0.31952037 0.153613416 -0.103203311 #> [3,] 0.4006711 -0.09731989 1.00000000 0.39624791 -0.192037439 0.176212444 #> [4,] -0.1986926 -0.31952037 0.39624791 1.00000000 -0.209640163 0.246450494 #> [5,] 0.4322485 0.15361342 -0.19203744 -0.20964016 1.000000000 -0.002892377 #> [6,] 0.2055191 -0.10320331 0.17621244 0.24645049 -0.002892377 1.000000000 #> [7,] -0.2156807 0.59139279 0.13859641 -0.40092438 -0.414228998 -0.079212164 #> [8,] -0.3018880 -0.19825248 -0.03367939 -0.40314191 -0.138046668 -0.444760974 #> [9,] 0.3690050 -0.11110492 0.69602694 -0.05780996 -0.147455094 0.508497704 #> [10,] -0.3851162 -0.14703686 0.12601100 0.23068886 -0.295237109 -0.215708752 #> [,7] [,8] [,9] [,10] #> [1,] -0.21568066 -0.30188805 0.36900501 -0.3851162 #> [2,] 0.59139279 -0.19825248 -0.11110492 -0.1470369 #> [3,] 0.13859641 -0.03367939 0.69602694 0.1260110 #> [4,] -0.40092438 -0.40314191 -0.05780996 0.2306889 #> [5,] -0.41422900 -0.13804667 -0.14745509 -0.2952371 #> [6,] -0.07921216 -0.44476097 0.50849770 -0.2157088 #> [7,] 1.00000000 0.25945424 0.36872314 0.1762733 #> [8,] 0.25945424 1.00000000 -0.03329687 0.2664217 #> [9,] 0.36872314 -0.03329687 1.00000000 -0.1398469 #> [10,] 0.17627333 0.26642168 -0.13984694 1.0000000
correlation(x)
#> Calculating pearson correlation matrix.
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 1.0000000 0.11769600 0.40067107 -0.19869260 0.432248547 0.205519098 #> [2,] 0.1176960 1.00000000 -0.09731989 -0.31952037 0.153613416 -0.103203311 #> [3,] 0.4006711 -0.09731989 1.00000000 0.39624791 -0.192037439 0.176212444 #> [4,] -0.1986926 -0.31952037 0.39624791 1.00000000 -0.209640163 0.246450494 #> [5,] 0.4322485 0.15361342 -0.19203744 -0.20964016 1.000000000 -0.002892377 #> [6,] 0.2055191 -0.10320331 0.17621244 0.24645049 -0.002892377 1.000000000 #> [7,] -0.2156807 0.59139279 0.13859641 -0.40092438 -0.414228998 -0.079212164 #> [8,] -0.3018880 -0.19825248 -0.03367939 -0.40314191 -0.138046668 -0.444760974 #> [9,] 0.3690050 -0.11110492 0.69602694 -0.05780996 -0.147455094 0.508497704 #> [10,] -0.3851162 -0.14703686 0.12601100 0.23068886 -0.295237109 -0.215708752 #> [,7] [,8] [,9] [,10] #> [1,] -0.21568066 -0.30188805 0.36900501 -0.3851162 #> [2,] 0.59139279 -0.19825248 -0.11110492 -0.1470369 #> [3,] 0.13859641 -0.03367939 0.69602694 0.1260110 #> [4,] -0.40092438 -0.40314191 -0.05780996 0.2306889 #> [5,] -0.41422900 -0.13804667 -0.14745509 -0.2952371 #> [6,] -0.07921216 -0.44476097 0.50849770 -0.2157088 #> [7,] 1.00000000 0.25945424 0.36872314 0.1762733 #> [8,] 0.25945424 1.00000000 -0.03329687 0.2664217 #> [9,] 0.36872314 -0.03329687 1.00000000 -0.1398469 #> [10,] 0.17627333 0.26642168 -0.13984694 1.0000000
stats::cor(x = c(x), y = c(y))
#> [1] 0.9634786
correlation(x = x, y = y)
#> Calculating pearson correlation on 100 values.
#> [1] 0.9634786
## SummarizedExperiment ==== x <- list[["SummarizedExperiment_x"]] y <- list[["SummarizedExperiment_y"]] correlation(x = x, i = 1L)
#> Calculating pearson correlation matrix.
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 1.0000000 0.11769600 0.40067107 -0.19869260 0.432248547 0.205519098 #> [2,] 0.1176960 1.00000000 -0.09731989 -0.31952037 0.153613416 -0.103203311 #> [3,] 0.4006711 -0.09731989 1.00000000 0.39624791 -0.192037439 0.176212444 #> [4,] -0.1986926 -0.31952037 0.39624791 1.00000000 -0.209640163 0.246450494 #> [5,] 0.4322485 0.15361342 -0.19203744 -0.20964016 1.000000000 -0.002892377 #> [6,] 0.2055191 -0.10320331 0.17621244 0.24645049 -0.002892377 1.000000000 #> [7,] -0.2156807 0.59139279 0.13859641 -0.40092438 -0.414228998 -0.079212164 #> [8,] -0.3018880 -0.19825248 -0.03367939 -0.40314191 -0.138046668 -0.444760974 #> [9,] 0.3690050 -0.11110492 0.69602694 -0.05780996 -0.147455094 0.508497704 #> [10,] -0.3851162 -0.14703686 0.12601100 0.23068886 -0.295237109 -0.215708752 #> [,7] [,8] [,9] [,10] #> [1,] -0.21568066 -0.30188805 0.36900501 -0.3851162 #> [2,] 0.59139279 -0.19825248 -0.11110492 -0.1470369 #> [3,] 0.13859641 -0.03367939 0.69602694 0.1260110 #> [4,] -0.40092438 -0.40314191 -0.05780996 0.2306889 #> [5,] -0.41422900 -0.13804667 -0.14745509 -0.2952371 #> [6,] -0.07921216 -0.44476097 0.50849770 -0.2157088 #> [7,] 1.00000000 0.25945424 0.36872314 0.1762733 #> [8,] 0.25945424 1.00000000 -0.03329687 0.2664217 #> [9,] 0.36872314 -0.03329687 1.00000000 -0.1398469 #> [10,] 0.17627333 0.26642168 -0.13984694 1.0000000
correlation(x = x, i = 1L, j = 2L)
#> Calculating pearson correlation on 100 values.
#> [1] 0.9634786
correlation(x = x, y = y)
#> Calculating pearson correlation on 100 values.
#> [1] 0.9634786