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 to similarity metrics.
Arguments
- dissimilarity
the output object from
dissimilarity()
orsimilarity_to_dissimilarity()
.- 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 similarity
metric(s) between 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)Euclidean similarity = 1 / (1 - Euclidean distance)
Otherwise, all other columns will be transformed into dissimilarity with the following formula:
similarity = 1 - dissimilaritysimilarity = 1 - dissimilarity
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)
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.5 0.4444444 0.33333333 0.2857143 0.9378490 0.9033233
#> 3 Site1 Site3 0.4 0.2500000 0.25000000 0.1428571 0.8202953 0.7839879
#> 4 Site1 Site4 0.3 0.0000000 0.17647059 0.0000000 0.8400640 0.8300765
#> 5 Site1 Site5 0.3 0.0000000 0.17647059 0.0000000 0.9199781 0.8897281
#> 8 Site2 Site3 0.3 0.2222222 0.17647059 0.1250000 0.7950150 0.7434104
#> 9 Site2 Site4 0.2 0.0000000 0.11111111 0.0000000 0.9577039 0.9286321
#> 10 Site2 Site5 0.2 0.0000000 0.11111111 0.0000000 0.5441406 0.4980645
#> 14 Site3 Site4 0.1 0.0000000 0.05263158 0.0000000 0.8386034 0.7918437
#> 15 Site3 Site5 0.1 0.0000000 0.05263158 0.0000000 0.5932122 0.5422270
#> 20 Site4 Site5 0.0 0.0000000 0.00000000 0.0000000 0.7121645 0.5717927
#> Euclidean a b c A B C
#> 2 1598.485 5 2 3 128 1196 2667
#> 3 1215.801 6 1 3 286 1038 1573
#> 4 1208.155 7 0 3 200 1124 977
#> 5 1465.220 7 0 3 146 1178 2179
#> 8 1553.991 7 1 2 477 2318 1382
#> 9 1632.567 8 0 2 84 2711 1093
#> 10 1121.744 8 0 2 1167 1628 1158
#> 14 1317.810 9 0 1 245 1614 932
#> 15 1199.365 9 0 1 851 1008 1474
#> 20 1310.670 10 0 0 504 673 1821
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.5 0.5555556 0.6666667 0.7142857 0.06215101 0.09667674
#> 3 Site1 Site3 0.6 0.7500000 0.7500000 0.8571429 0.17970468 0.21601208
#> 4 Site1 Site4 0.7 1.0000000 0.8235294 1.0000000 0.15993603 0.16992353
#> 5 Site1 Site5 0.7 1.0000000 0.8235294 1.0000000 0.08002192 0.11027190
#> 8 Site2 Site3 0.7 0.7777778 0.8235294 0.8750000 0.20498496 0.25658956
#> 9 Site2 Site4 0.8 1.0000000 0.8888889 1.0000000 0.04229607 0.07136788
#> 10 Site2 Site5 0.8 1.0000000 0.8888889 1.0000000 0.45585937 0.50193548
#> 14 Site3 Site4 0.9 1.0000000 0.9473684 1.0000000 0.16139657 0.20815633
#> 15 Site3 Site5 0.9 1.0000000 0.9473684 1.0000000 0.40678776 0.45777300
#> 20 Site4 Site5 1.0 1.0000000 1.0000000 1.0000000 0.28783552 0.42820731
#> Euclidean a b c A B C
#> 2 0.0006252014 5 2 3 128 1196 2667
#> 3 0.0008218268 6 1 3 286 1038 1573
#> 4 0.0008270237 7 0 3 200 1124 977
#> 5 0.0006820257 7 0 3 146 1178 2179
#> 8 0.0006430905 7 1 2 477 2318 1382
#> 9 0.0006121572 8 0 2 84 2711 1093
#> 10 0.0008906748 8 0 2 1167 1628 1158
#> 14 0.0007582592 9 0 1 245 1614 932
#> 15 0.0008330801 9 0 1 851 1008 1474
#> 20 0.0007623868 10 0 0 504 673 1821