Distances of Points to Class Centroids
centredist.Rd
Function finds Euclidean or squared Mahalanobis distances of points
to class centroids in betadisper
or ordination results.
Usage
# Default S3 method
centredist(x, group, distance = c("euclidean",
"mahalanobis"), display = "sites", w, ...)
# S3 method for class 'betadisper'
centredist(x, ...)
# S3 method for class 'cca'
centredist(x, group, distance = c("euclidean", "mahalanobis"),
display = c("sites", "species"), rank = 2, ...)
# S3 method for class 'rda'
centredist(x, group, distance = c("euclidean", "mahalanobis"),
display = "sites", rank = 2, ...)
# S3 method for class 'dbrda'
centredist(x, group, distance = c("euclidean","mahalanobis"),
display = "sites", rank = 2, ...)
# S3 method for class 'wcmdscale'
centredist(x, group, distance= c("euclidean","mahalanobis"),
display = "sites", rank = 2, ...)
Arguments
- x
An ordination result object, or a matrix for the default method or a
betadisper
result object.- group
Factor to define classes for which centroids are found.
- distance
Use either simple Euclidean distance or squared Mahalanobis distances that take into account the shape of covariance ellipses.
- display
Kind of
scores
.- w
Weights. If
x
has weights (such ascca
result), these will be used.- rank
Number of axes used in ordination methods.
- ...
Other arguments to functions (ignored).
Details
Function finds either simple Euclidean distances of all points to
their centroid as given by argument group
or squared
Mahalanobis distances of points to the centroid. In addition to the
distances, it returns information of the original group and the
nearest group for each point.
Currently the distances are scaled so that the sum of squared
Euclidean distance will give the residual (unexplained) eigenvalue
in constrained ordination with given group. The distances may not
correspond to the distances in ordination plots with specific
scaling
and setting argument scaling
gives an
error. Due to restriction of this scaling, Euclidean distances for
species scores are only allowed in ca
and
cca
. These restrictions may be relaxed in the future
versions of the method.
Squared Mahalanobis distances (mahalanobis
) are scaled
by the within group covariance matrix, and they are consistent with
ordiellipse
.
Mahalanobis distances can only be calculated for group
that
are larger than rank
. For rank = 2
, minimum
permissible group
has three points. However, even this can
fail in degenerate cases, such as three points on a line. Euclidean
distances can be calculated for any rank
. With rank = "full"
distance-based methods wcmdscale
, pco
,
dbrda
and betadisper
will handle
negative eigenvalues and associated eigenvectors, but with numeric
rank they will only use real eigenvectors with positive eigenvalues.
There are specific methods for some ordination models, but many will
be handled by the default method (including metaMDS
and monoMDS
).
The specific method for betadisper
ignores most
arguments and calculates the distances as specified in model
fitting. The betadisper
result with argument
type = "centroid"
is equal to wcmdscale
,
pco
or dbrda
with the same
group
and rank = "full"
.
Value
Function returns a list with components
- centre
Centre to which a point was originally allocated.
- nearest
Nearest centre to a point.
- distances
Distance matrix where each observation point is a row, and column gives the distance of the point to that centre.
See also
betadisper
, goodness.cca
,
mahalanobis
and various ordination methods.
Examples
data(dune, dune.env)
d <- vegdist(dune) # Bray-Curtis
mod <- with(dune.env, betadisper(d, Management))
centredist(mod)
#>
#> distances: bray
#>
#> centre nearest BF HF NM SF
#> 1 SF BF 0.49644568 0.5418457 0.8517511 0.5644371
#> 2 BF BF 0.25251672 0.3780172 0.7075570 0.4114648
#> 3 SF SF 0.41470128 0.3855665 0.6204737 0.1110907
#> 4 SF SF 0.42624976 0.4393619 0.6358864 0.2266270
#> 5 HF HF 0.37738597 0.2087227 0.6498706 0.5146204
#> 6 HF HF 0.34039792 0.2456723 0.6126336 0.5642756
#> 7 HF HF 0.29310989 0.1150411 0.6612193 0.4818030
#> 8 HF SF 0.50164812 0.4375138 0.4274640 0.2449894
#> 9 HF SF 0.53148596 0.3887899 0.5918427 0.2614780
#> 10 BF BF 0.03881034 0.2868014 0.6154078 0.5175787
#> 11 BF BF 0.36741961 0.4427340 0.5443921 0.5525589
#> 12 SF SF 0.67759762 0.5249557 0.5627151 0.3810054
#> 13 SF SF 0.67165475 0.5651190 0.5987912 0.3495776
#> 14 NM NM 0.75201600 0.7713289 0.4241926 0.6703521
#> 15 NM NM 0.81690124 0.7245346 0.3013518 0.6254642
#> 16 SF NM 0.86797919 0.7654150 0.4951610 0.5510415
#> 17 NM NM 0.66496238 0.6792701 0.6563399 0.8377509
#> 18 NM BF 0.44376561 0.5052147 0.5074504 0.6320749
#> 19 NM NM 0.67278867 0.6880656 0.5126987 0.7579196
#> 20 NM NM 0.86808311 0.7719325 0.3037948 0.6683067
## equal to metric scaling when using centroids instead of medians
modc <- with(dune.env, betadisper(d, Management, type = "centroid"))
ord <- pco(d)
all.equal(centredist(modc), centredist(ord, dune.env$Management, rank="full"),
check.attributes = FALSE)
#> [1] TRUE