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 to
dissimilarity metrics (beta diversity).
Arguments
- similarity
the output object from
similarity()
ordissimilarity_to_similarity()
.- include_formula
a
boolean
indicating if the metrics based on your own formula(s) should be converted (see Details). This argument is set toTRUE
by default.
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\)
Author
Maxime Lenormand (maxime.lenormand@inrae.fr), Boris Leroy (leroy.boris@gmail.com) and 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.7 0.7777778 0.8235294 0.8750000 0.21060383 0.32062780
#> 3 Site1 Site3 0.9 1.0000000 0.9473684 1.0000000 0.17193948 0.27412281
#> 4 Site1 Site4 0.7 0.7777778 0.8235294 0.8750000 0.05630499 0.06052963
#> 5 Site1 Site5 0.8 0.8000000 0.8888889 0.8888889 0.49366325 0.89692982
#> 8 Site2 Site3 0.8 1.0000000 0.8888889 1.0000000 0.17280917 0.47309417
#> 9 Site2 Site4 0.6 0.6000000 0.7500000 0.7500000 0.08555287 0.11883408
#> 10 Site2 Site5 0.7 0.7777778 0.8235294 0.8750000 0.30126404 0.96188341
#> 14 Site3 Site4 0.8 1.0000000 0.8888889 1.0000000 0.31050556 0.54602774
#> 15 Site3 Site5 0.9 1.0000000 0.9473684 1.0000000 0.20100045 0.22144289
#> 20 Site4 Site5 0.7 0.7777778 0.8235294 0.8750000 0.15273865 0.30769231
#> Euclidean a b c A B C
#> 2 0.0019339025 7 2 1 143 769 303
#> 3 0.0008485920 9 0 1 250 662 1746
#> 4 0.0015518958 7 2 1 48 864 745
#> 5 0.0009916059 8 1 1 818 94 1584
#> 8 0.0009110112 8 0 2 211 235 1785
#> 9 0.0021393869 6 2 2 53 393 740
#> 10 0.0009764204 7 1 2 429 17 1973
#> 14 0.0009843675 8 2 0 433 1563 360
#> 15 0.0006513612 9 1 0 442 1554 1960
#> 20 0.0008078410 7 1 2 244 549 2158
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.3 0.2222222 0.17647059 0.1250000 0.7893962 0.67937220
#> 3 Site1 Site3 0.1 0.0000000 0.05263158 0.0000000 0.8280605 0.72587719
#> 4 Site1 Site4 0.3 0.2222222 0.17647059 0.1250000 0.9436950 0.93947037
#> 5 Site1 Site5 0.2 0.2000000 0.11111111 0.1111111 0.5063368 0.10307018
#> 8 Site2 Site3 0.2 0.0000000 0.11111111 0.0000000 0.8271908 0.52690583
#> 9 Site2 Site4 0.4 0.4000000 0.25000000 0.2500000 0.9144471 0.88116592
#> 10 Site2 Site5 0.3 0.2222222 0.17647059 0.1250000 0.6987360 0.03811659
#> 14 Site3 Site4 0.2 0.0000000 0.11111111 0.0000000 0.6894944 0.45397226
#> 15 Site3 Site5 0.1 0.0000000 0.05263158 0.0000000 0.7989995 0.77855711
#> 20 Site4 Site5 0.3 0.2222222 0.17647059 0.1250000 0.8472613 0.69230769
#> Euclidean a b c A B C
#> 2 516.0891 7 2 1 143 769 303
#> 3 1177.4226 9 0 1 250 662 1746
#> 4 643.3731 7 2 1 48 864 745
#> 5 1007.4651 8 1 1 818 94 1584
#> 8 1096.6814 8 0 2 211 235 1785
#> 9 466.4236 6 2 2 53 393 740
#> 10 1023.1491 7 1 2 429 17 1973
#> 14 1014.8808 8 2 0 433 1563 360
#> 15 1534.2464 9 1 0 442 1554 1960
#> 20 1236.8674 7 1 2 244 549 2158