Skip to contents

This function converts a data.frame of dissimilarity metrics (beta diversity) between sites into similarity metrics.

Usage

dissimilarity_to_similarity(dissimilarity, include_formula = TRUE)

Arguments

dissimilarity

the output object from dissimilarity() or similarity_to_dissimilarity().

include_formula

a boolean indicating whether metrics based on custom formula(s) should also be converted (see Details). The default is TRUE.

Value

A data.frame with the additional class bioregion.pairwise, 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("s", 1:5)
colnames(comat) <- paste0("sp", 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     s1    s2 0.3000000   0.0000000 0.1764706 0.0000000 0.7519084 0.5379147
#> 3     s1    s3 0.3333333   0.2500000 0.2000000 0.1428571 0.6119266 0.5893204
#> 4     s1    s4 0.3333333   0.2500000 0.2000000 0.1428571 0.8736196 0.7854167
#> 5     s1    s5 0.3333333   0.2500000 0.2000000 0.1428571 0.5719801 0.4147813
#> 8     s2    s3 0.2000000   0.0000000 0.1111111 0.0000000 0.5068871 0.1516588
#> 9     s2    s4 0.2000000   0.0000000 0.1111111 0.0000000 0.8447894 0.8341232
#> 10    s2    s5 0.2000000   0.0000000 0.1111111 0.0000000 0.6442396 0.5426540
#> 14    s3    s4 0.4000000   0.4000000 0.2500000 0.2500000 0.9099338 0.8583333
#> 15    s3    s5 0.2222222   0.2222222 0.1250000 0.1250000 0.5735381 0.4555053
#> 20    s4    s5 0.2222222   0.2222222 0.1250000 0.1250000 0.8285214 0.7958333
#>    Euclidean a b c   A    B   C
#> 2   573.3550 7 0 3 195  955 227
#> 3   601.5862 6 1 2 423  727 607
#> 4   689.8246 6 1 2 103 1047 377
#> 5   526.3411 6 1 2 388  762 275
#> 8   333.8053 8 2 0 358   64 672
#> 9   399.5973 8 2 0  70  352 410
#> 10  310.5978 8 2 0 193  229 470
#> 14  611.8660 6 2 2  68  962 412
#> 15  485.2061 7 1 1 361  669 302
#> 20  456.2510 7 1 1  98  382 565

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     s1    s2 0.7000000   1.0000000 0.8235294 1.0000000 0.24809160 0.4620853
#> 3     s1    s3 0.6666667   0.7500000 0.8000000 0.8571429 0.38807339 0.4106796
#> 4     s1    s4 0.6666667   0.7500000 0.8000000 0.8571429 0.12638037 0.2145833
#> 5     s1    s5 0.6666667   0.7500000 0.8000000 0.8571429 0.42801986 0.5852187
#> 8     s2    s3 0.8000000   1.0000000 0.8888889 1.0000000 0.49311295 0.8483412
#> 9     s2    s4 0.8000000   1.0000000 0.8888889 1.0000000 0.15521064 0.1658768
#> 10    s2    s5 0.8000000   1.0000000 0.8888889 1.0000000 0.35576037 0.4573460
#> 14    s3    s4 0.6000000   0.6000000 0.7500000 0.7500000 0.09006623 0.1416667
#> 15    s3    s5 0.7777778   0.7777778 0.8750000 0.8750000 0.42646190 0.5444947
#> 20    s4    s5 0.7777778   0.7777778 0.8750000 0.8750000 0.17147857 0.2041667
#>      Euclidean a b c   A    B   C
#> 2  0.001741083 7 0 3 195  955 227
#> 3  0.001659514 6 1 2 423  727 607
#> 4  0.001447545 6 1 2 103 1047 377
#> 5  0.001896306 6 1 2 388  762 275
#> 8  0.002986810 8 2 0 358   64 672
#> 9  0.002496272 8 2 0  70  352 410
#> 10 0.003209265 8 2 0 193  229 470
#> 14 0.001631678 6 2 2  68  962 412
#> 15 0.002056741 7 1 1 361  669 302
#> 20 0.002186983 7 1 1  98  382 565