Correlate chromatograms
Source:R/methods-Chromatogram.R
, R/methods-MChromatograms.R
correlate-Chromatogram.Rd
For xcms
>= 3.15.3 please use compareChromatograms()
instead of
correlate
Correlate intensities of two chromatograms with each other. If the two
Chromatogram
objects have different retention times they are first
aligned to match data points in the first to data points in the second
chromatogram. See help on alignRt
in MSnbase::Chromatogram()
for more
details.
If correlate
is called on a single MChromatograms()
object a pairwise
correlation of each chromatogram with each other is performed and a matrix
with the correlation coefficients is returned.
Note that the correlation of two chromatograms depends also on their order,
e.g. correlate(chr1, chr2)
might not be identical to
correlate(chr2, chr1)
. The lower and upper triangular part of the
correlation matrix might thus be different.
Usage
# S4 method for class 'Chromatogram,Chromatogram'
correlate(
x,
y,
use = "pairwise.complete.obs",
method = c("pearson", "kendall", "spearman"),
align = c("closest", "approx"),
...
)
# S4 method for class 'MChromatograms,missing'
correlate(
x,
y = NULL,
use = "pairwise.complete.obs",
method = c("pearson", "kendall", "spearman"),
align = c("closest", "approx"),
...
)
# S4 method for class 'MChromatograms,MChromatograms'
correlate(
x,
y = NULL,
use = "pairwise.complete.obs",
method = c("pearson", "kendall", "spearman"),
align = c("closest", "approx"),
...
)
Arguments
- x
Chromatogram()
orMChromatograms()
object.- y
Chromatogram()
orMChromatograms()
object.- use
character(1)
passed to thecor
function. Seecor()
for details.- method
character(1)
passed to thecor
function. Seecor()
for details.- align
character(1)
defining the alignment method to be used. See help onalignRt
inMSnbase::Chromatogram()
for details. The value of this parameter is passed to themethod
parameter ofalignRt
.- ...
optional parameters passed along to the
alignRt
method such astolerance
that, if set to0
requires the retention times to be identical.
Value
numeric(1)
or matrix
(if called on MChromatograms
objects)
with the correlation coefficient. If a matrix
is returned, the rows
represent the chromatograms in x
and the columns the chromatograms in
y
.
Examples
library(MSnbase)
chr1 <- Chromatogram(rtime = 1:10 + rnorm(n = 10, sd = 0.3),
intensity = c(5, 29, 50, NA, 100, 12, 3, 4, 1, 3))
chr2 <- Chromatogram(rtime = 1:10 + rnorm(n = 10, sd = 0.3),
intensity = c(80, 50, 20, 10, 9, 4, 3, 4, 1, 3))
chr3 <- Chromatogram(rtime = 3:9 + rnorm(7, sd = 0.3),
intensity = c(53, 80, 130, 15, 5, 3, 2))
chrs <- MChromatograms(list(chr1, chr2, chr3))
## Using `compareChromatograms` instead of `correlate`.
compareChromatograms(chr1, chr2)
#> [1] -0.09306005
compareChromatograms(chr2, chr1)
#> [1] -0.09306005
compareChromatograms(chrs, chrs)
#> [,1] [,2] [,3]
#> [1,] 1.00000000 -0.09306005 0.9887213
#> [2,] -0.09306005 1.00000000 0.5018044
#> [3,] 0.99355819 0.50180442 1.0000000