Convert dissimilarity metrics to similarity metrics
Source:R/similarity_dissimilarity_conversion.R
dissimilarity_to_similarity.Rd
This function converts a data.frame
of dissimilarity metrics
(beta diversity) between sites into similarity metrics.
Arguments
- dissimilarity
the output object from
dissimilarity()
orsimilarity_to_dissimilarity()
.- 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 the additional class
bioregion.pairwise.metric
, providing similarity metrics for each pair of
sites based on a dissimilarity 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
dissimilarity()
) or not in the original list of dissimilarity metrics
(argument metrics
in dissimilarity()
) 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
, the similarity will be calculated based
on the following formula:
Euclidean similarity = 1 / (1 - Euclidean distance)
Otherwise, all other columns will be transformed into dissimilarity with the following formula:
similarity = 1 - dissimilarity
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: similarity dissimilarity_to_similarity
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)
dissimil <- dissimilarity(comat, metric = "all")
dissimil
#> 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.8018942 0.6449788
#> 3 Site1 Site3 0.1000000 0.0000000 0.05263158 0.0000000 0.6067015 0.6052922
#> 4 Site1 Site4 0.3000000 0.2222222 0.17647059 0.1250000 0.9532681 0.9447761
#> 5 Site1 Site5 0.2000000 0.2000000 0.11111111 0.1111111 0.6848320 0.6201423
#> 8 Site2 Site3 0.2000000 0.0000000 0.11111111 0.0000000 0.8564062 0.7439887
#> 9 Site2 Site4 0.4000000 0.4000000 0.25000000 0.2500000 0.7899365 0.6958982
#> 10 Site2 Site5 0.1111111 0.0000000 0.05882353 0.0000000 0.6163216 0.1089109
#> 14 Site3 Site4 0.2000000 0.0000000 0.11111111 0.0000000 0.7729867 0.7328358
#> 15 Site3 Site5 0.1000000 0.0000000 0.05263158 0.0000000 0.7226144 0.6642778
#> 20 Site4 Site5 0.3000000 0.2222222 0.17647059 0.1250000 0.5026806 0.2731343
#> Euclidean a b c A B C
#> 2 962.1434 7 2 1 251 1576 456
#> 3 978.7129 9 0 1 716 1111 1098
#> 4 1189.3666 7 2 1 74 1753 1266
#> 5 1239.4765 8 1 1 694 1133 1883
#> 8 957.2549 8 0 2 181 526 1633
#> 9 719.4282 6 2 2 215 492 1125
#> 10 929.6322 8 0 1 630 77 1947
#> 14 1060.9401 8 2 0 358 1456 982
#> 15 1326.5221 9 1 0 609 1205 1968
#> 20 947.1806 7 1 2 974 366 1603
similarity <- dissimilarity_to_similarity(dissimil)
similarity
#> 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.19810576 0.35502122
#> 3 Site1 Site3 0.9000000 1.0000000 0.9473684 1.0000000 0.39329854 0.39470783
#> 4 Site1 Site4 0.7000000 0.7777778 0.8235294 0.8750000 0.04673192 0.05522388
#> 5 Site1 Site5 0.8000000 0.8000000 0.8888889 0.8888889 0.31516803 0.37985769
#> 8 Site2 Site3 0.8000000 1.0000000 0.8888889 1.0000000 0.14359381 0.25601132
#> 9 Site2 Site4 0.6000000 0.6000000 0.7500000 0.7500000 0.21006351 0.30410184
#> 10 Site2 Site5 0.8888889 1.0000000 0.9411765 1.0000000 0.38367844 0.89108911
#> 14 Site3 Site4 0.8000000 1.0000000 0.8888889 1.0000000 0.22701332 0.26716418
#> 15 Site3 Site5 0.9000000 1.0000000 0.9473684 1.0000000 0.27738556 0.33572216
#> 20 Site4 Site5 0.7000000 0.7777778 0.8235294 0.8750000 0.49731938 0.72686567
#> Euclidean a b c A B C
#> 2 0.0010382669 7 2 1 251 1576 456
#> 3 0.0010207072 9 0 1 716 1111 1098
#> 4 0.0008400773 7 2 1 74 1753 1266
#> 5 0.0008061418 8 1 1 694 1133 1883
#> 8 0.0010435636 8 0 2 181 526 1633
#> 9 0.0013880633 6 2 2 215 492 1125
#> 10 0.0010745384 8 0 1 630 77 1947
#> 14 0.0009416727 8 2 0 358 1456 982
#> 15 0.0007532831 9 1 0 609 1205 1968
#> 20 0.0010546515 7 1 2 974 366 1603