https://github.com/cran/CluMix
Raw File
Tip revision: 0d1b46ce56f99be7b8c9412c34b720b0794a8ce6 authored by Manuela Hummel on 03 March 2016, 20:29:17 UTC
version 0.3
Tip revision: 0d1b46c
dist.subjects.R
dist.subjects <-
function(data){
#function(data, type=list()){
# !! to be done: allow also asymmetric binary variables
  
  # if all variables are numeric, use Euclidean distance
  dc <- sapply(data, data.class)
  if(all(dc == "numeric"))
    D <- dist(data)
  
  # if not, use Gower's distance with Podani's extension
  else{
    # !! depending on type, define asymmetric binary variables for parameter asym.bin  
  
    # binary variables have to be numeric
    K <- sapply(data[,dc == "factor", drop=FALSE], function(x) length(levels(x)))
    bin <- names(K)[K == 2]
    data[,bin] <- sapply(data[,bin], function(x) as.numeric(x) - 1)
  
    D <- FD::gowdis(x=data, ord="metric") # asym.bin=!!
  }
  return(D)
}
back to top