Convert similarity metrics to dissimilarity metrics
Source:R/similarity_dissimilarity_conversion.R
similarity_to_dissimilarity.Rd
This function converts a data.frame
of similarity metrics between sites
into dissimilarity metrics (beta diversity).
Arguments
- similarity
The output object from
similarity()
ordissimilarity_to_similarity()
.- include_formula
A
boolean
indicating whether metrics based on custom formula(s) should also be converted (see Details). The default isTRUE
.
Value
A data.frame
with additional class
bioregion.pairwise
, providing dissimilarity
metric(s) between each pair of sites based on a similarity object.
Note
The behavior of this function changes depending on column names. Columns
Site1
and Site2
are copied identically. If there are columns called
a
, b
, c
, A
, B
, C
they will also be copied identically. If there
are columns based on your own formula (argument formula
in similarity()
)
or not in the original list of similarity metrics (argument metrics
in
similarity()
) and if the argument include_formula
is set to FALSE
,
they will also be copied identically. Otherwise there are going to be
converted like they other columns (default behavior).
If a column is called Euclidean
, its distance will be calculated based
on the following formula:
Euclidean distance = (1 - Euclidean similarity) / Euclidean similarity
Otherwise, all other columns will be transformed into dissimilarity with the following formula:
dissimilarity = 1 - similarity
See also
For more details illustrated with a practical example, see the vignette: https://biorgeo.github.io/bioregion/articles/a3_pairwise_metrics.html.
Associated functions: dissimilarity similarity_to_dissimilarity
Author
Maxime Lenormand (maxime.lenormand@inrae.fr)
Boris Leroy (leroy.boris@gmail.com)
Pierre Denelle (pierre.denelle@gmail.com)
Examples
comat <- matrix(sample(0:1000, size = 50, replace = TRUE,
prob = 1 / 1:1001), 5, 10)
rownames(comat) <- paste0("s", 1:5)
colnames(comat) <- paste0("sp", 1:10)
simil <- similarity(comat, metric = "all")
simil
#> Data.frame of similarity between sites
#> - Total number of sites: 5
#> - Total number of species: 10
#> - Number of rows: 10
#> - Number of similarity metrics: 7
#>
#>
#> Site1 Site2 Jaccard Jaccardturn Sorensen Simpson Bray Brayturn
#> 2 s1 s2 0.6666667 1.0000000 0.8000000 1.0000000 0.14954683 0.16445183
#> 3 s1 s3 0.5000000 0.7142857 0.6666667 0.8333333 0.07591241 0.12956811
#> 4 s1 s4 0.6250000 0.7142857 0.7692308 0.8333333 0.23641070 0.24596050
#> 5 s1 s5 0.5555556 0.7142857 0.7142857 0.8333333 0.15248401 0.25747508
#> 8 s2 s3 0.8000000 0.8000000 0.8888889 0.8888889 0.37885057 0.57063712
#> 9 s2 s4 0.6000000 0.7500000 0.7500000 0.8571429 0.15324472 0.17594255
#> 10 s2 s5 0.7000000 0.7777778 0.8235294 0.8750000 0.51927543 0.77423823
#> 14 s3 s4 0.6000000 0.7500000 0.7500000 0.8571429 0.20597015 0.37163375
#> 15 s3 s5 0.7000000 0.7777778 0.8235294 0.8750000 0.31553398 0.31795947
#> 20 s4 s5 0.5000000 0.5555556 0.6666667 0.7142857 0.04426559 0.07899461
#> Euclidean a b c A B C
#> 2 0.002157589 6 0 3 99 503 623
#> 3 0.001250767 5 1 4 78 524 1375
#> 4 0.002461588 5 1 2 137 465 420
#> 5 0.001090607 5 1 3 155 447 1276
#> 8 0.001473415 8 1 1 412 310 1041
#> 9 0.002130648 6 3 1 98 624 459
#> 10 0.001582132 7 2 1 559 163 872
#> 14 0.001356957 6 3 1 207 1246 350
#> 15 0.001194697 7 2 1 455 998 976
#> 20 0.001084698 5 2 3 44 513 1387
dissimilarity <- similarity_to_dissimilarity(simil)
dissimilarity
#> Data.frame of dissimilarity between sites
#> - Total number of sites: 5
#> - Total number of species: 10
#> - Number of rows: 10
#> - Number of dissimilarity metrics: 7
#>
#>
#> Site1 Site2 Jaccard Jaccardturn Sorensen Simpson Bray Brayturn
#> 2 s1 s2 0.3333333 0.0000000 0.2000000 0.0000000 0.8504532 0.8355482
#> 3 s1 s3 0.5000000 0.2857143 0.3333333 0.1666667 0.9240876 0.8704319
#> 4 s1 s4 0.3750000 0.2857143 0.2307692 0.1666667 0.7635893 0.7540395
#> 5 s1 s5 0.4444444 0.2857143 0.2857143 0.1666667 0.8475160 0.7425249
#> 8 s2 s3 0.2000000 0.2000000 0.1111111 0.1111111 0.6211494 0.4293629
#> 9 s2 s4 0.4000000 0.2500000 0.2500000 0.1428571 0.8467553 0.8240575
#> 10 s2 s5 0.3000000 0.2222222 0.1764706 0.1250000 0.4807246 0.2257618
#> 14 s3 s4 0.4000000 0.2500000 0.2500000 0.1428571 0.7940299 0.6283662
#> 15 s3 s5 0.3000000 0.2222222 0.1764706 0.1250000 0.6844660 0.6820405
#> 20 s4 s5 0.5000000 0.4444444 0.3333333 0.2857143 0.9557344 0.9210054
#> Euclidean a b c A B C
#> 2 462.4803 6 0 3 99 503 623
#> 3 798.5092 5 1 4 78 524 1375
#> 4 405.2419 5 1 2 137 465 420
#> 5 915.9208 5 1 3 155 447 1276
#> 8 677.6954 8 1 1 412 310 1041
#> 9 468.3407 6 3 1 98 624 459
#> 10 631.0586 7 2 1 559 163 872
#> 14 735.9429 6 3 1 207 1246 350
#> 15 836.0323 7 2 1 455 998 976
#> 20 920.9158 5 2 3 44 513 1387