similarity: 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")
Value
The similarity between x and y.
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:
# NOT RUN {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")
# }