I am trying to calculate the Jaccard Index of an array/DataFrame using the package Distance.jl, and am having difficulty.
using Distances, DataFrames
zxcv = [0.0 0.0 1.0;0.0 0.0 1.0;0.0 0.0 0.0]
dist = evaluate(jaccard(),zxcv[:,1],zxcv[:,2]) # error no method matching jaccard
In R the formula is
zxcv<-c(0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0)
dim(zxcv)<-c(3,3)
trophic.sim = function(web){
# compute trophic similarity (Jaccard index)
# using the cocitation matrix approach
# cocite defines the cardinal of the intersection of prey and preds
cocite = web%*%t(web) + t(web)%*%web # |a inter b|
# now calculate union as |a| + |b| - |a inter b|
web.degree = colSums(web) + rowSums(web) # |a| + |b|
nb_s = nrow(web)
sum.degree = outer(web.degree,web.degree, FUN = '+') # sum.degree contains |a| + |b|
web.union = sum.degree - cocite
obs.trophic.sim = cocite / web.union
return(obs.trophic.sim)
}
mat.similarity = trophic.sim(zxcv)
Could someone show me how to use the Distance package correctly, or what the R code would look like in Julia?