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.9 1.0000000 0.9473684 1.0000000 0.5824034 0.9685939
#> 3 Site1 Site3 0.8 0.8000000 0.8888889 0.8888889 0.2562450 0.3404711
#> 4 Site1 Site4 0.7 0.7777778 0.8235294 0.8750000 0.2195872 0.2853881
#> 5 Site1 Site5 1.0 1.0000000 1.0000000 1.0000000 0.4940603 0.5788722
#> 8 Site2 Site3 0.9 1.0000000 0.9473684 1.0000000 0.2375918 0.2855297
#> 9 Site2 Site4 0.8 1.0000000 0.8888889 1.0000000 0.1272068 0.3002283
#> 10 Site2 Site5 0.9 1.0000000 0.9473684 1.0000000 0.3664657 0.5005313
#> 14 Site3 Site4 0.7 0.7777778 0.8235294 0.8750000 0.1025641 0.1872146
#> 15 Site3 Site5 0.8 0.8000000 0.8888889 0.8888889 0.3196955 0.3570670
#> 20 Site4 Site5 0.7 0.7777778 0.8235294 0.8750000 0.1834663 0.2888128
#> Euclidean a b c A B C
#> 2 0.0009516283 9 0 1 1357 44 1902
#> 3 0.0008056575 8 1 1 477 924 1845
#> 4 0.0010034300 7 2 1 250 1151 626
#> 5 0.0012235856 9 0 0 811 590 1071
#> 8 0.0005732502 9 1 0 663 2596 1659
#> 9 0.0006133316 8 2 0 263 2996 613
#> 10 0.0007442002 9 1 0 942 2317 940
#> 14 0.0007731009 7 2 1 164 2158 712
#> 15 0.0007658530 8 1 1 672 1650 1210
#> 20 0.0009768194 7 1 2 253 623 1629
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.1 0.0000000 0.05263158 0.0000000 0.4175966 0.03140614
#> 3 Site1 Site3 0.2 0.2000000 0.11111111 0.1111111 0.7437550 0.65952891
#> 4 Site1 Site4 0.3 0.2222222 0.17647059 0.1250000 0.7804128 0.71461187
#> 5 Site1 Site5 0.0 0.0000000 0.00000000 0.0000000 0.5059397 0.42112777
#> 8 Site2 Site3 0.1 0.0000000 0.05263158 0.0000000 0.7624082 0.71447028
#> 9 Site2 Site4 0.2 0.0000000 0.11111111 0.0000000 0.8727932 0.69977169
#> 10 Site2 Site5 0.1 0.0000000 0.05263158 0.0000000 0.6335343 0.49946865
#> 14 Site3 Site4 0.3 0.2222222 0.17647059 0.1250000 0.8974359 0.81278539
#> 15 Site3 Site5 0.2 0.2000000 0.11111111 0.1111111 0.6803045 0.64293305
#> 20 Site4 Site5 0.3 0.2222222 0.17647059 0.1250000 0.8165337 0.71118721
#> Euclidean a b c A B C
#> 2 1049.8305 9 0 1 1357 44 1902
#> 3 1240.2222 8 1 1 477 924 1845
#> 4 995.5817 7 2 1 250 1151 626
#> 5 816.2702 9 0 0 811 590 1071
#> 8 1743.4388 9 1 0 663 2596 1659
#> 9 1629.4395 8 2 0 263 2996 613
#> 10 1342.7245 9 1 0 942 2317 940
#> 14 1292.4922 7 2 1 164 2158 712
#> 15 1304.7337 8 1 1 672 1650 1210
#> 20 1022.7307 7 1 2 253 623 1629