R/centering.R

Defines functions Ucenter Dcenter

Documented in Dcenter Ucenter

## use the Rcpp exported function U_center or D_center
## the utilities in this file are provided for reference and historical reasons

Dcenter <- function(x) {
  ## x is a dist object or data matrix
  if (!inherits(x, "dist")) x <- dist(x)
  d <- as.matrix(x)
  n <- nrow(d)
  m <- rowSums(d)
  M <- sum(m) / n^2
  m <- m / n
  a <- sweep(d, 1, m)
  b <- sweep(a, 2, m)
  B <- b + M
}

Ucenter <- function(x) {
  ## x is a dist object or data matrix
  if (!inherits(x, "dist")) x <- dist(x)
  d <- as.matrix(x)
  n <- nrow(d)
  m <- rowSums(d)
  M <- sum(m) / ((n-1)*(n-2))
  m <- m / (n-2)
  a <- sweep(d, 1, m)
  b <- sweep(a, 2, m)
  B <- b + M
  diag(B) <- 0
  B
}

Try the energy package in your browser

Any scripts or data that you put into this service are public.

energy documentation built on Dec. 28, 2022, 1:43 a.m.