Double-center a distance matrix
Source:R/double_center_distance_matrix.R
double_center_distance_matrix.RdDouble-centers a distance matrix by converting it to weights and centering to zero row and column means. Required for computing Moran's Eigenvector Maps.
Value
Double-centered numeric matrix with the same dimensions as distance.matrix. The matrix has row means and column means of zero.
Details
Double-centering is performed in two steps:
Convert distances to weights using
weights_from_distance_matrix()Center the matrix: subtract row means, subtract column means, and add the grand mean
The resulting matrix is symmetric with zero row and column means, suitable for Moran's Eigenvector Maps computation.
Examples
data(plants_distance)
# Double-center the distance matrix
centered <- double_center_distance_matrix(
distance.matrix = plants_distance
)
# Verify row means are zero
head(rowMeans(centered))
#> 1 2 3 4 5
#> -1.184503e-19 1.150114e-18 1.299132e-19 9.361393e-19 1.085157e-18
#> 6
#> 2.445425e-19
# Verify column means are zero
head(colMeans(centered))
#> 1 2 3 4 5 6
#> 2.025118e-19 2.598264e-19 1.108083e-19 2.502740e-19 3.668138e-19 5.234738e-19