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)
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.8 1.0000000 0.8888889 1.000 0.2324665 0.6427015
#> 3 Site1 Site3 0.7 0.7777778 0.8235294 0.875 0.0903852 0.1223317
#> 4 Site1 Site4 0.8 1.0000000 0.8888889 1.000 0.1058132 0.1168831
#> 5 Site1 Site5 0.8 1.0000000 0.8888889 1.000 0.2622122 0.3149022
#> 8 Site2 Site3 0.9 1.0000000 0.9473684 1.000 0.1836613 0.3355120
#> 9 Site2 Site4 1.0 1.0000000 1.0000000 1.000 0.1116717 0.3616558
#> 10 Site2 Site5 1.0 1.0000000 1.0000000 1.000 0.1307930 0.2766885
#> 14 Site3 Site4 0.9 1.0000000 0.9473684 1.000 0.4774920 0.7315271
#> 15 Site3 Site5 0.9 1.0000000 0.9473684 1.000 0.3361718 0.3727422
#> 20 Site4 Site5 1.0 1.0000000 1.0000000 1.000 0.5053790 0.6810519
#> Euclidean a b c A B C
#> 2 0.0009814101 8 0 2 295 1784 164
#> 3 0.0007215210 7 1 2 149 1930 1069
#> 4 0.0006827220 8 0 2 243 1836 2271
#> 5 0.0009173381 8 0 2 467 1612 1016
#> 8 0.0010484706 9 1 0 154 305 1064
#> 9 0.0008964378 10 0 0 166 293 2348
#> 10 0.0012192118 10 0 0 127 332 1356
#> 14 0.0011265904 9 0 1 891 327 1623
#> 15 0.0010358347 9 0 1 454 764 1029
#> 20 0.0011055029 10 0 0 1010 1504 473
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.2 0.0000000 0.11111111 0.000 0.7675335 0.3572985
#> 3 Site1 Site3 0.3 0.2222222 0.17647059 0.125 0.9096148 0.8776683
#> 4 Site1 Site4 0.2 0.0000000 0.11111111 0.000 0.8941868 0.8831169
#> 5 Site1 Site5 0.2 0.0000000 0.11111111 0.000 0.7377878 0.6850978
#> 8 Site2 Site3 0.1 0.0000000 0.05263158 0.000 0.8163387 0.6644880
#> 9 Site2 Site4 0.0 0.0000000 0.00000000 0.000 0.8883283 0.6383442
#> 10 Site2 Site5 0.0 0.0000000 0.00000000 0.000 0.8692070 0.7233115
#> 14 Site3 Site4 0.1 0.0000000 0.05263158 0.000 0.5225080 0.2684729
#> 15 Site3 Site5 0.1 0.0000000 0.05263158 0.000 0.6638282 0.6272578
#> 20 Site4 Site5 0.0 0.0000000 0.00000000 0.000 0.4946210 0.3189481
#> Euclidean a b c A B C
#> 2 1017.9420 8 0 2 295 1784 164
#> 3 1384.9610 7 1 2 149 1930 1069
#> 4 1463.7250 8 0 2 243 1836 2271
#> 5 1089.1106 8 0 2 467 1612 1016
#> 8 952.7702 9 1 0 154 305 1064
#> 9 1114.5264 10 0 0 166 293 2348
#> 10 819.2021 10 0 0 127 332 1356
#> 14 886.6341 9 0 1 891 327 1623
#> 15 964.4050 9 0 1 454 764 1029
#> 20 903.5657 10 0 0 1010 1504 473