distance among matrix columns with freely choosable distance function

Share:

Description

distance among matrix columns with freely choosable distance function

Usage

1
distmy(x, func, init = NA, diag = TRUE)

Arguments

x

data

func

function taking 2 arrays x, y

init

how to initialize the output matrix

diag

should the diagonal be also computed

Value

matrix with dist[i,j] = func(x[,i],[x,j])

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
mat = matrix(rnorm(10*5000),ncol=10)
redist = distmy(mat,function(x,y){mean(abs(x-y))},init=NA,diag=FALSE)
image(redist)
redist = distmy(mat,cor,init=0,diag=FALSE)
image(redist)
redist = distmy(mat,function(x,y){ks.test(x,y)$p.value},init=1,diag=TRUE)
image(redist)
hist(uppertriang(redist))
range(uppertriang(redist))
which(redist < 0.05 , arr.ind = TRUE)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.