Compute the covariance or correlation between (the corresponding pixel values in) several images.
cov.im(..., use = "complete.obs", method = c("pearson", "kendall", "spearman"))
cor.im(..., use = "complete.obs", method = c("pearson", "kendall", "spearman"))
A symmetric matrix.
The arguments ...
should be pixel images (objects of class "im"
).
Their spatial domains must overlap, but need not have the same
pixel dimensions.
These functions compute the covariance or correlation between the corresponding pixel values in the images given.
The pixel images are converted to a common pixel resolution (by resampling). Then the corresponding pixel values of each image are extracted. Finally the correlation or covariance between the pixel values of each pair of images, at corresponding pixels, is computed.
The result is a symmetric matrix with one row and column for each image.
The [i,j]
entry is the correlation or covariance between
the i
th and j
th images in the argument list.
The row names and column names of the matrix are copied from the
argument names if they were given (i.e. if the arguments were given
as name=value
).
The argument use
specifies how to handle NA
values.
A pixel value of NA
is assigned to any
pixel falling outside the spatial domain of an image
(i.e. outside the window in which the image is defined).
If any one of the image arguments ...
is defined on a
non-rectangular window, or if the image arguments are not all defined
on the same window, then the data will contain NA
values.
Options for the argument use
are documented in the help file
for cov
and cor
.
use="complete.obs"
(the default):
calculations are based on those pixels which lie inside the intersection
of the windows of all the images. An error occurs if the
intersection is empty.
use="na.or.complete"
:
calculations are based on those pixels which lie inside the intersection
of the windows of all the images. If the
intersection is empty, a matrix of NA
values is returned.
use="pairwise.complete.obs"
: the calculation of the
covariance or correlation between each pair of images is
based on the pixels which lie in the intersection of the
windows of those two images. Only available when method="pearson"
.
The resulting matrix may not be positive definite.
use="everything"
: the calculation is based on all
pixels, but any calculation of variance or covariance or correlation
that includes an NA
value gives an NA
result in the
corresponding entry in the matrix.
use="all.obs"
: the calculation is based on all pixels,
and an error occurs if any pixel has an NA
value in any image.
Note that cor
and cov
are not generic, so you have to type cor.im
, cov.im
.