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.metric
, 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("Site", 1:5)
colnames(comat) <- paste0("Species", 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 Site1 Site2 0.7000000 0.7777778 0.8235294 0.8750000 0.22441993 0.25213675
#> 3 Site1 Site3 0.8000000 0.8000000 0.8888889 0.8888889 0.31751996 0.35245047
#> 4 Site1 Site4 0.8000000 0.8000000 0.8888889 0.8888889 0.18467583 0.28119658
#> 5 Site1 Site5 0.8000000 0.8000000 0.8888889 0.8888889 0.25753705 0.32020330
#> 8 Site2 Site3 0.7000000 0.7777778 0.8235294 0.8750000 0.03556658 0.04483837
#> 9 Site2 Site4 0.8888889 1.0000000 0.9411765 1.0000000 0.46780893 0.61754626
#> 10 Site2 Site5 0.7000000 0.7777778 0.8235294 0.8750000 0.09973286 0.14231258
#> 14 Site3 Site4 0.8000000 0.8000000 0.8888889 0.8888889 0.06264916 0.10948905
#> 15 Site3 Site5 0.8000000 0.8000000 0.8888889 0.8888889 0.13631157 0.15120712
#> 20 Site4 Site5 0.8000000 0.8000000 0.8888889 0.8888889 0.23270440 0.47013977
#> Euclidean a b c A B C
#> 2 0.0011451633 7 2 1 295 875 1164
#> 3 0.0011979205 8 1 1 338 832 621
#> 4 0.0008944035 8 1 1 329 841 2064
#> 5 0.0012432343 8 1 1 252 918 535
#> 8 0.0008641731 7 1 2 43 1416 916
#> 9 0.0011208034 8 0 1 901 558 1492
#> 10 0.0010267693 7 1 2 112 1347 675
#> 14 0.0007422345 8 1 1 105 854 2288
#> 15 0.0010031767 8 1 1 119 840 668
#> 20 0.0009457680 8 1 1 370 2023 417
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 Site1 Site2 0.3000000 0.2222222 0.17647059 0.1250000 0.7755801 0.7478632
#> 3 Site1 Site3 0.2000000 0.2000000 0.11111111 0.1111111 0.6824800 0.6475495
#> 4 Site1 Site4 0.2000000 0.2000000 0.11111111 0.1111111 0.8153242 0.7188034
#> 5 Site1 Site5 0.2000000 0.2000000 0.11111111 0.1111111 0.7424630 0.6797967
#> 8 Site2 Site3 0.3000000 0.2222222 0.17647059 0.1250000 0.9644334 0.9551616
#> 9 Site2 Site4 0.1111111 0.0000000 0.05882353 0.0000000 0.5321911 0.3824537
#> 10 Site2 Site5 0.3000000 0.2222222 0.17647059 0.1250000 0.9002671 0.8576874
#> 14 Site3 Site4 0.2000000 0.2000000 0.11111111 0.1111111 0.9373508 0.8905109
#> 15 Site3 Site5 0.2000000 0.2000000 0.11111111 0.1111111 0.8636884 0.8487929
#> 20 Site4 Site5 0.2000000 0.2000000 0.11111111 0.1111111 0.7672956 0.5298602
#> Euclidean a b c A B C
#> 2 872.2379 7 2 1 295 875 1164
#> 3 833.7799 8 1 1 338 832 621
#> 4 1117.0636 8 1 1 329 841 2064
#> 5 803.3536 8 1 1 252 918 535
#> 8 1156.1756 7 1 2 43 1416 916
#> 9 891.2171 8 0 1 901 558 1492
#> 10 972.9286 7 1 2 112 1347 675
#> 14 1346.2830 8 1 1 105 854 2288
#> 15 995.8333 8 1 1 119 840 668
#> 20 1056.3418 8 1 1 370 2023 417