Search code examples
rmatlabcluster-analysishierarchical-clustering

COSH distance in R


I have a matrix of 3600x513 and i want to determine the distances between the rows to be able to cluster. My problem is I want to use the COSH distance, which is not available in the dist() function of R.

My questions are:

  1. is it possible to create my own COSH function and call it on the dist() function and afterwards use the hclust() function?
  2. I have another matrix with the COSH distances calculated by MATLAB. can i replace the values of the output of dist() with the distances i calculated before?

Solution

  • I'll just add the post from CrossValidated for visibility (original post):

    set.seed(1)
    mat <- matrix(runif(5))
    fn <- function(x, y) 1 - cos(x - y)
    
    proxy::dist(mat, method = fn)
    

    proxy lets you use dist with a custom function