R/My_DCOR.R

#' my program to get distance correlation
#'
#' @param A, doubly centered matrix from get_doublyCenterDist(x, index)$mat
#' @param B, doubly centered matrix from get_doublyCenterDist(x, index)$mat
#' @param dVarX, doubly centered matrix from get_doublyCenterDist(x, index)$dVar
#' @param dVarY, doubly centered matrix from get_doublyCenterDist(x, index)$dVar
#' @return the P-values of SPC and aSPC tests
#' @references Xu Z., Pan W. An adaptive and powerful test for two groups of variables with high dimension
#' @examples
#' library(mvtnorm)
#' sigma = diag(0.9, 10) + 0.1
#' n = 500 # sample size
#' Z = rmvnorm(n=n, mean=rep(0,10), sigma=sigma)
#' X = rmvnorm(n=n, mean=rep(0,25), sigma=diag(1, 25))
#' Y = rmvnorm(n=n, mean=rep(0,25), sigma=diag(1, 25))
#' X = as.data.frame(cbind(Z[,1:5], X))
#' Y = as.data.frame(cbind(Z[,6:10], Y))
#' dim(X)
#' dim(Y)
#' set.seed(123) # to ensure we can replicate the permutation P-value
#'
#' a = proc.time()
#' aSPC_dcor(X, Y, pow = c(1:8, Inf), B = 50)
#' proc.time() - a
#'
#' a = proc.time()
#' aSPC(X, Y, pow = c(1:8, Inf), B = 50, method = "dcor_fast")
#' proc.time() - a
#'
#' a = proc.time()
#' aSPC(X, Y, pow = c(1:8, Inf), B = 50, method = "dcor")
#' proc.time() - a
#' @export
#' @importFrom energy dcor

My_DCOR = function (A, B, dVarX, dVarY)
{

  dCov <- sqrt(mean(A * B))
  V <- sqrt(dVarX * dVarY)
  if (V > 0) dCor <- dCov/V else dCor <- 0

  return(dCor = dCor)
}
jasonzyx/aSPC documentation built on May 18, 2019, 5:55 p.m.