R/dist2bin.R

Defines functions dist2bin

Documented in dist2bin

#' Calculate the agreement-based measurement
#' 
#' Calculate the agreement-based measurement of two any pair-wise samples x_i and x_j for binary variables
#' 
#' @param X A sample-feature matrix with rows as samples and columns as features
#' 
#' @param C The same as X
#' 
#' @return A matrix whose elements at (i,j) is the agreement-based measurement of two any pair-wise samples x_i and x_j
#' @author Xiaoyao Yin
#' @examples 
#' 
#' data_list <- simu_data_gen()
#' X <- data_list[[1]]
#' C <- X
#' Diff <- dist2bin(X,C)
#' @rdname dist2bin
#' @export
dist2bin <- function(X,C) {
  ndata = nrow(X)
  ncentres = nrow(C)

  res = matrix(0,ndata,ncentres)
  for (i in 1:ndata) 
  {
  	for (j in 1:ncentres) 
  	{
  		res[i,j] = sum(X[i,]!=C[j,])
  	}
  }
  return(res)
}

Try the M2SMF package in your browser

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

M2SMF documentation built on Jan. 11, 2020, 9:28 a.m.