similarity {neighbr} | R Documentation |
Calculate the similarity between two vectors of logicals.
Description
Calculate the similarity between two vectors of logicals.
Usage
similarity(x, y, measure)
Arguments
x , y |
Logical or numeric vectors. |
measure |
Similarity measure ("simple_matching", "jaccard", or "tanimoto") |
Details
Input vectors must consist of logical or numeric elements TRUE,FALSE or 0,1 (not factors). Similarity measures in this package are based on those defined in the PMML specification. Similarity ranges from 0 (no similarity) to 1 (identical).
For logical vectors x
and y
, we define the following:
a11
= number of times where x_i=1 and y_i=1
a10
= number of times where x_i=1 and y_i=0
a01
= number of times where x_i=0 and y_i=1
a00
= number of times where x_i=0 and y_i=0
Similarities are calculated using the following formulas:
Simple matching: (a11 + a00) / (a11 + a10 + a01 + a00)
Jaccard: (a11) / (a11 + a10 + a01)
Tanimoto: (a11 + a00) / (a11 + 2 * (a10 + a01) + a00)
Value
The similarity between x
and y
.
See Also
distance
,
PMML comparison measures
Examples
similarity(c(0,1,1),c(0,0,1),"simple_matching")
similarity(c(0,1,1),c(0,0,1),"jaccard")
similarity(as.logical(c(0,1,1)),as.logical(c(0,0,1)),"tanimoto")