1## use the Rcpp exported function U_center or D_center 2## the utilities in this file are provided for reference and historical reasons 3 4Dcenter <- function(x) { 5 ## x is a dist object or data matrix 6 if (!inherits(x, "dist")) x <- dist(x) 7 d <- as.matrix(x) 8 n <- nrow(d) 9 m <- rowSums(d) 10 M <- sum(m) / n^2 11 m <- m / n 12 a <- sweep(d, 1, m) 13 b <- sweep(a, 2, m) 14 B <- b + M 15} 16 17Ucenter <- function(x) { 18 ## x is a dist object or data matrix 19 if (!inherits(x, "dist")) x <- dist(x) 20 d <- as.matrix(x) 21 n <- nrow(d) 22 m <- rowSums(d) 23 M <- sum(m) / ((n-1)*(n-2)) 24 m <- m / (n-2) 25 a <- sweep(d, 1, m) 26 b <- sweep(a, 2, m) 27 B <- b + M 28 diag(B) <- 0 29 B 30} 31 32