Skip to content
Permalink
339bb5649d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
29 lines (23 sloc) 798 Bytes
#' Function to compute double-centred distance matrices
#'
#' @param x is a vector containing the values of a variable
#'
#' @return Dcentered vactor for x
#'
#' @examples
#' Dcenter(c(1,2,3,4))
#'
#' @export
############################################################
### Function to compute double-centred distance matrices ###
############################################################
Dcenter <- function(x) {
# x is a vector containing the values of a variable
n <- length(x) # number of points in dimension of x
# compute distance matrix a
a <- outer(x, x, function(x1, x2) abs(x1 - x2))
# normalise a
ahat <- a - matrix(rowMeans(a), nrow = n, ncol = n) - matrix(colMeans(a), nrow = n, ncol = n, byrow = TRUE) + mean(a)
#return(ahat[!upper.tri(ahat)])
return(ahat)
}