R/corr_dis.R

Defines functions corr_dis

Documented in corr_dis

#' Correlation distance matrix between points
#'
#' Computes the correlation distance between n points in m dimensions
#' ,or two points with same dimensions.
#'
#' @param x Numeric vector, or a matrix with size n x m.
#' @param y Optional input. Numeric vector; must be the same length as x. If no input of y,
#'          please specify all other parameters to avoid confusion.
#' @param output Format of output, either matrix or dist object. Default is matrix.
#'
#' @return Correlation distance matrix or object, centered form of cosine distance between points
#'
#' @examples
#' corr_dis(x = matrix(c(1, 2, 3, 4), 2, 2), output = "dist")
#'
#' corr_dis(rnorm(10), rnorm(10))
#'
#' @export
#'

corr_dis <- function(x, y, output = "matrix"){

  # standardize input
  m = input_format(x, y)
  mean_m = m - rowMeans(m)
  # use cosine distance function to calculate
  dis = cos_dis(mean_m)

  return(output_format(dis, output))
}
yingtliu/distPack documentation built on Jan. 1, 2021, 1:45 p.m.