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 similarityEuclidean distance = (1 - Euclidean similarity) / Euclidean similarity
Otherwise, all other columns will be transformed into dissimilarity with the following formula:
dissimilarity = 1 - similaritydissimilarity = 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.9000000 1.0000000 0.9473684 1.0000000 0.1720905 0.1723757
#> 3 Site1 Site3 0.7000000 1.0000000 0.8235294 1.0000000 0.2281580 0.2298206
#> 4 Site1 Site4 0.8000000 1.0000000 0.8888889 1.0000000 0.6596702 0.7292818
#> 5 Site1 Site5 0.8000000 1.0000000 0.8888889 1.0000000 0.1948339 0.2933333
#> 8 Site2 Site3 0.6000000 0.7500000 0.7500000 0.8571429 0.1866667 0.1883408
#> 9 Site2 Site4 0.7000000 0.7777778 0.8235294 0.8750000 0.3692615 0.4074890
#> 10 Site2 Site5 0.7000000 0.7777778 0.8235294 0.8750000 0.2179676 0.3288889
#> 14 Site3 Site4 0.5000000 0.5555556 0.6666667 0.7142857 0.1257545 0.1401345
#> 15 Site3 Site5 0.6666667 0.7500000 0.8000000 0.8571429 0.5722802 0.8533333
#> 20 Site4 Site5 0.6000000 0.6000000 0.7500000 0.7500000 0.1785252 0.3066667
#> Euclidean a b c A B C
#> 2 0.001502900 9 1 0 156 749 752
#> 3 0.001246094 7 3 0 205 700 687
#> 4 0.003214051 8 2 0 660 245 436
#> 5 0.001605213 8 2 0 132 773 318
#> 8 0.001449036 6 3 1 168 740 724
#> 9 0.001493722 7 2 1 370 538 726
#> 10 0.002367092 7 2 1 148 760 302
#> 14 0.001118991 5 2 3 125 767 971
#> 15 0.002782594 6 1 2 384 508 66
#> 20 0.001426095 6 2 2 138 958 312
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.1000000 0.0000000 0.05263158 0.0000000 0.8279095 0.8276243
#> 3 Site1 Site3 0.3000000 0.0000000 0.17647059 0.0000000 0.7718420 0.7701794
#> 4 Site1 Site4 0.2000000 0.0000000 0.11111111 0.0000000 0.3403298 0.2707182
#> 5 Site1 Site5 0.2000000 0.0000000 0.11111111 0.0000000 0.8051661 0.7066667
#> 8 Site2 Site3 0.4000000 0.2500000 0.25000000 0.1428571 0.8133333 0.8116592
#> 9 Site2 Site4 0.3000000 0.2222222 0.17647059 0.1250000 0.6307385 0.5925110
#> 10 Site2 Site5 0.3000000 0.2222222 0.17647059 0.1250000 0.7820324 0.6711111
#> 14 Site3 Site4 0.5000000 0.4444444 0.33333333 0.2857143 0.8742455 0.8598655
#> 15 Site3 Site5 0.3333333 0.2500000 0.20000000 0.1428571 0.4277198 0.1466667
#> 20 Site4 Site5 0.4000000 0.4000000 0.25000000 0.2500000 0.8214748 0.6933333
#> Euclidean a b c A B C
#> 2 664.3802 9 1 0 156 749 752
#> 3 801.5080 7 3 0 205 700 687
#> 4 310.1338 8 2 0 660 245 436
#> 5 621.9703 8 2 0 132 773 318
#> 8 689.1139 6 3 1 168 740 724
#> 9 668.4684 7 2 1 370 538 726
#> 10 421.4594 7 2 1 148 760 302
#> 14 892.6623 5 2 3 125 767 971
#> 15 358.3769 6 1 2 384 508 66
#> 20 700.2157 6 2 2 138 958 312