Skip to contents

This function converts a data.frame of dissimilarity metrics (beta diversity) between sites to 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 if the metrics based on your own formula(s) should be converted (see Details). This argument is set to TRUE 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)\)

Otherwise, all other columns will be transformed into dissimilarity with the following formula:

\(similarity = 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.1000000        0.00 0.05263158 0.0000000 0.6143387 0.5678670
#> 3  Site1 Site3 0.3000000        0.00 0.17647059 0.0000000 0.9301381 0.9205910
#> 4  Site1 Site4 0.1000000        0.00 0.05263158 0.0000000 0.9103098 0.9101852
#> 5  Site1 Site5 0.1000000        0.00 0.05263158 0.0000000 0.8822202 0.7590028
#> 8  Site2 Site3 0.2222222        0.00 0.12500000 0.0000000 0.9383033 0.9375000
#> 9  Site2 Site4 0.2000000        0.20 0.11111111 0.1111111 0.8803630 0.8657407
#> 10 Site2 Site5 0.2000000        0.20 0.11111111 0.1111111 0.7958662 0.6436012
#> 14 Site3 Site4 0.4000000        0.25 0.25000000 0.1428571 0.4631964 0.3888889
#> 15 Site3 Site5 0.4000000        0.25 0.25000000 0.1428571 0.6438240 0.3894126
#> 20 Site4 Site5 0.2000000        0.20 0.11111111 0.1111111 0.6780312 0.3398148
#>    Euclidean a b c   A    B    C
#> 2   803.6697 9 1 0 468  615  876
#> 3  1045.7256 7 3 0  86  997 1293
#> 4  1051.6116 9 1 0  97  986  983
#> 5  1631.1229 9 1 0 261  822 3088
#> 8  1007.0447 7 2 0  84 1260 1295
#> 9   982.6363 8 1 1 145 1199  935
#> 10 1543.2715 8 1 1 479  865 2870
#> 14  604.8330 6 1 3 660  719  420
#> 15 1422.3600 6 1 3 842  537 2507
#> 20 1463.9505 8 1 1 713  367 2636

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.9000000        1.00 0.9473684 1.0000000 0.38566131 0.43213296
#> 3  Site1 Site3 0.7000000        1.00 0.8235294 1.0000000 0.06986190 0.07940905
#> 4  Site1 Site4 0.9000000        1.00 0.9473684 1.0000000 0.08969025 0.08981481
#> 5  Site1 Site5 0.9000000        1.00 0.9473684 1.0000000 0.11777978 0.24099723
#> 8  Site2 Site3 0.7777778        1.00 0.8750000 1.0000000 0.06169666 0.06250000
#> 9  Site2 Site4 0.8000000        0.80 0.8888889 0.8888889 0.11963696 0.13425926
#> 10 Site2 Site5 0.8000000        0.80 0.8888889 0.8888889 0.20413382 0.35639881
#> 14 Site3 Site4 0.6000000        0.75 0.7500000 0.8571429 0.53680358 0.61111111
#> 15 Site3 Site5 0.6000000        0.75 0.7500000 0.8571429 0.35617597 0.61058738
#> 20 Site4 Site5 0.8000000        0.80 0.8888889 0.8888889 0.32196884 0.66018519
#>       Euclidean a b c   A    B    C
#> 2  0.0012427459 9 1 0 468  615  876
#> 3  0.0009553602 7 3 0  86  997 1293
#> 4  0.0009500180 9 1 0  97  986  983
#> 5  0.0006126989 9 1 0 261  822 3088
#> 8  0.0009920195 7 2 0  84 1260 1295
#> 9  0.0010166360 8 1 1 145 1199  935
#> 10 0.0006475545 8 1 1 479  865 2870
#> 14 0.0016506198 6 1 3 660  719  420
#> 15 0.0007025629 6 1 3 842  537 2507
#> 20 0.0006826169 8 1 1 713  367 2636