Correlation
Usage
correlation(x, y, ...)
# 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 SummarizedExperiment,SummarizedExperiment
correlation(x, y, i = 1L, 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 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 numeric,numeric
correlation(x, y, method = c("pearson", "kendall", "spearman"))
Arguments
- x
Object.
- y
Object.
- method
character(1)
. Which correlation coefficient (or covariance) is to be computed. Seestats::cor
documentation for details.- i
integer(1)
orcharacter(1)
. ForSummarizedExperiment
, primary assay.- j
integer(1)
,character(1)
, orNULL
. ForSummarizedExperiment
, optional secondary assay. IfNULL
, calculates correlation matrix only on the primary assay.- ...
Additional arguments.
Examples
data(correlation, package = "AcidTest")
list <- correlation
## vector ====
x <- list[["vector_x"]]
y <- list[["vector_y"]]
head(x)
#> [1] 2 0 13 4 0 0
head(y)
#> [1] 0.6764552 -1.4776467 12.2839279 5.6912999 0.6343433 -1.3237125
correlation(x = x, y = y)
#> → Calculating pearson correlation on 100 values.
#> [1] 0.9679586
## matrix ====
x <- list[["matrix_x"]]
y <- list[["matrix_y"]]
head(x)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 2 6 5 11 2 5 1 6 6 12
#> [2,] 0 1 1 0 7 1 3 11 3 10
#> [3,] 13 8 5 2 11 20 3 0 11 0
#> [4,] 4 11 2 0 5 0 6 0 2 7
#> [5,] 0 6 7 12 4 8 0 1 2 8
#> [6,] 0 3 2 4 3 2 0 5 2 1
head(y)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.6764552 6.7416244 4.2135584 12.0503339 3.707114 4.8705682 2.7809390
#> [2,] -1.4776467 -0.2459721 2.0902830 -0.8709795 8.391184 -0.6895169 1.0254373
#> [3,] 12.2839279 8.7796431 6.8375315 0.6215681 12.572532 20.3227114 3.4789913
#> [4,] 5.6912999 9.9169030 3.8624108 -0.7437612 3.901034 -0.6705214 7.4041131
#> [5,] 0.6343433 4.4000908 7.8159738 13.1496279 4.170519 8.5612456 -0.1770829
#> [6,] -1.3237125 3.7288806 0.4820749 3.4867973 3.290924 0.4683960 1.9713020
#> [,8] [,9] [,10]
#> [1,] 4.6695525 7.5618775 13.5023073
#> [2,] 10.1064177 2.4153431 8.5226743
#> [3,] 1.9143920 11.7381091 0.2995024
#> [4,] 1.7281752 3.8499412 6.8724791
#> [5,] -0.3568263 2.8111183 9.0378596
#> [6,] 4.8216451 0.2424011 -0.5963026
stats::cor(x)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.00000000 0.21949625 0.07673707 -0.23830635 0.56219887 0.67943447
#> [2,] 0.21949625 1.00000000 -0.08216896 -0.26708240 0.14688956 -0.12196990
#> [3,] 0.07673707 -0.08216896 1.00000000 0.67762067 -0.31897134 0.48293916
#> [4,] -0.23830635 -0.26708240 0.67762067 1.00000000 -0.28132202 0.14167981
#> [5,] 0.56219887 0.14688956 -0.31897134 -0.28132202 1.00000000 0.02092915
#> [6,] 0.67943447 -0.12196990 0.48293916 0.14167981 0.02092915 1.00000000
#> [7,] -0.14286756 0.58348668 0.05348282 -0.42961395 -0.36256807 -0.03802021
#> [8,] -0.46637804 -0.17939287 -0.23504641 -0.17128379 -0.19686818 -0.40768671
#> [9,] 0.44358958 -0.09919878 0.56591105 0.04540479 -0.19316915 0.75430968
#> [10,] -0.41321717 -0.13006618 0.47160156 0.41826854 -0.35612505 -0.30511159
#> [,7] [,8] [,9] [,10]
#> [1,] -0.14286756 -0.4663780 0.44358958 -0.41321717
#> [2,] 0.58348668 -0.1793929 -0.09919878 -0.13006618
#> [3,] 0.05348282 -0.2350464 0.56591105 0.47160156
#> [4,] -0.42961395 -0.1712838 0.04540479 0.41826854
#> [5,] -0.36256807 -0.1968682 -0.19316915 -0.35612505
#> [6,] -0.03802021 -0.4076867 0.75430968 -0.30511159
#> [7,] 1.00000000 0.1779272 0.34940884 0.07851239
#> [8,] 0.17792721 1.0000000 -0.17173085 0.43610035
#> [9,] 0.34940884 -0.1717308 1.00000000 0.02120542
#> [10,] 0.07851239 0.4361004 0.02120542 1.00000000
correlation(x)
#> → Calculating "pearson" correlation matrix.
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.00000000 0.21949625 0.07673707 -0.23830635 0.56219887 0.67943447
#> [2,] 0.21949625 1.00000000 -0.08216896 -0.26708240 0.14688956 -0.12196990
#> [3,] 0.07673707 -0.08216896 1.00000000 0.67762067 -0.31897134 0.48293916
#> [4,] -0.23830635 -0.26708240 0.67762067 1.00000000 -0.28132202 0.14167981
#> [5,] 0.56219887 0.14688956 -0.31897134 -0.28132202 1.00000000 0.02092915
#> [6,] 0.67943447 -0.12196990 0.48293916 0.14167981 0.02092915 1.00000000
#> [7,] -0.14286756 0.58348668 0.05348282 -0.42961395 -0.36256807 -0.03802021
#> [8,] -0.46637804 -0.17939287 -0.23504641 -0.17128379 -0.19686818 -0.40768671
#> [9,] 0.44358958 -0.09919878 0.56591105 0.04540479 -0.19316915 0.75430968
#> [10,] -0.41321717 -0.13006618 0.47160156 0.41826854 -0.35612505 -0.30511159
#> [,7] [,8] [,9] [,10]
#> [1,] -0.14286756 -0.4663780 0.44358958 -0.41321717
#> [2,] 0.58348668 -0.1793929 -0.09919878 -0.13006618
#> [3,] 0.05348282 -0.2350464 0.56591105 0.47160156
#> [4,] -0.42961395 -0.1712838 0.04540479 0.41826854
#> [5,] -0.36256807 -0.1968682 -0.19316915 -0.35612505
#> [6,] -0.03802021 -0.4076867 0.75430968 -0.30511159
#> [7,] 1.00000000 0.1779272 0.34940884 0.07851239
#> [8,] 0.17792721 1.0000000 -0.17173085 0.43610035
#> [9,] 0.34940884 -0.1717308 1.00000000 0.02120542
#> [10,] 0.07851239 0.4361004 0.02120542 1.00000000
stats::cor(x = c(x), y = c(y))
#> [1] 0.9679586
correlation(x = x, y = y)
#> → Calculating pearson correlation on 100 values.
#> [1] 0.9679586
## 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.00000000 0.21949625 0.07673707 -0.23830635 0.56219887 0.67943447
#> [2,] 0.21949625 1.00000000 -0.08216896 -0.26708240 0.14688956 -0.12196990
#> [3,] 0.07673707 -0.08216896 1.00000000 0.67762067 -0.31897134 0.48293916
#> [4,] -0.23830635 -0.26708240 0.67762067 1.00000000 -0.28132202 0.14167981
#> [5,] 0.56219887 0.14688956 -0.31897134 -0.28132202 1.00000000 0.02092915
#> [6,] 0.67943447 -0.12196990 0.48293916 0.14167981 0.02092915 1.00000000
#> [7,] -0.14286756 0.58348668 0.05348282 -0.42961395 -0.36256807 -0.03802021
#> [8,] -0.46637804 -0.17939287 -0.23504641 -0.17128379 -0.19686818 -0.40768671
#> [9,] 0.44358958 -0.09919878 0.56591105 0.04540479 -0.19316915 0.75430968
#> [10,] -0.41321717 -0.13006618 0.47160156 0.41826854 -0.35612505 -0.30511159
#> [,7] [,8] [,9] [,10]
#> [1,] -0.14286756 -0.4663780 0.44358958 -0.41321717
#> [2,] 0.58348668 -0.1793929 -0.09919878 -0.13006618
#> [3,] 0.05348282 -0.2350464 0.56591105 0.47160156
#> [4,] -0.42961395 -0.1712838 0.04540479 0.41826854
#> [5,] -0.36256807 -0.1968682 -0.19316915 -0.35612505
#> [6,] -0.03802021 -0.4076867 0.75430968 -0.30511159
#> [7,] 1.00000000 0.1779272 0.34940884 0.07851239
#> [8,] 0.17792721 1.0000000 -0.17173085 0.43610035
#> [9,] 0.34940884 -0.1717308 1.00000000 0.02120542
#> [10,] 0.07851239 0.4361004 0.02120542 1.00000000
correlation(x = x, i = 1L, j = 2L)
#> → Calculating pearson correlation on 100 values.
#> [1] 0.9679586
correlation(x = x, y = y)
#> → Calculating pearson correlation on 100 values.
#> [1] 0.9679586