This function computes and returns the distance matrix computed by using the specified distance measure to compute the distances between the rows of a data matrix containing circular data.
dist.circular(x, method = "correlation", diag = FALSE, upper = FALSE)
dist.circular
returns an object of class "dist"
.
The lower triangle of the distance matrix stored by columns in a
vector, say do
. If n
is the number of
observations, i.e., n <- attr(do, "Size")
, then
for \(i < j <= n\), the dissimilarity between (row) i and j is
do[n*(i-1) - i*(i-1)/2 + j-i]
.
The length of the vector is \(n*(n-1)/2\), i.e., of order \(n^2\).
The object has the following attributes (besides "class"
equal
to "dist"
):
integer, the number of observations in the dataset.
optionally, contains the labels, if any, of the observations of the dataset.
logicals corresponding to the arguments diag
and upper
above, specifying how the object should be printed.
optionally, the call
used to create the
object.
optionally, the distance method used; resulting from
dist.circular()
, the (match.arg()
ed) method
argument.
a numeric matrix of class circular
.
the distance measure to be used. This must be one of
"correlation"
, "angularseparation"
, "chord"
,
"geodesic"
. Any unambiguous substring can be given.
logical value indicating whether the diagonal of the
distance matrix should be printed by print.dist
.
logical value indicating whether the upper triangle of the
distance matrix should be printed by print.dist
.
Available distance measures are (written for two vectors \(x\) and \(y\)):
correlation
:\(\sqrt{1 - \rho}\) where \(\rho\) is the Circular Correlation coefficient defined as $$\frac{\sum_{i=1}^n \sin(x_i - \mu_x) \sin(y_i - \mu_y)}{\sqrt{\sum_{i=1}^n \sin^2(x_i - \mu_x) \sum_{i=1}^n \sin^2(y_i - \mu_y)}}$$ and \(\mu_x\), \(\mu_y\) are the mean direction of the two vectors
angularseparation
:\(\sum_{i=1}^n 1 - cos(x_i - y_i)\)
chord
:\(\sum_{i=1}^n \sqrt{2 (1 - \cos(x_i - y_i))}\)
geodesic
:\(\sum_{i=1}^n \pi - |\pi - |x_i - y_i||\) where the abs(x - y) is expressed with an angle in [-pi,pi]
Missing values are allowed, and are excluded from all computations
involving the rows within which they occur.
Further, when Inf
values are involved, all pairs of values are
excluded when their contribution to the distance gave NaN
or
NA
.
If some columns are excluded in calculating the sum is scaled up proportionally
to the number of columns used. If all pairs are excluded when calculating a
particular distance, the value is NA
.