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.metric, 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("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.1   0.0000000 0.05263158   0.000 0.6822366 0.36770692
#> 3  Site1 Site3     0.2   0.0000000 0.11111111   0.000 0.7912088 0.76797829
#> 4  Site1 Site4     0.0   0.0000000 0.00000000   0.000 0.7966491 0.39891452
#> 5  Site1 Site5     0.2   0.0000000 0.11111111   0.000 0.8986928 0.87381275
#> 8  Site2 Site3     0.3   0.2222222 0.17647059   0.125 0.8669680 0.77136515
#> 9  Site2 Site4     0.1   0.0000000 0.05263158   0.000 0.6014443 0.47222222
#> 10 Site2 Site5     0.3   0.2222222 0.17647059   0.125 0.7845220 0.67697907
#> 14 Site3 Site4     0.2   0.0000000 0.11111111   0.000 0.6195532 0.04550499
#> 15 Site3 Site5     0.4   0.4000000 0.25000000   0.250 0.8520000 0.83573807
#> 20 Site4 Site5     0.2   0.0000000 0.11111111   0.000 0.5867769 0.11282985
#>    Euclidean  a b c    A    B    C
#> 2   873.0229  9 1 0  466  271 1730
#> 3   668.8303  8 2 0  171  566  730
#> 4  1473.3516 10 0 0  443  294 3177
#> 5   846.5719  8 2 0   93  644 1006
#> 8  1208.8321  7 2 1  206 1990  695
#> 9  1462.9026  9 0 1 1159 1037 2461
#> 10 1246.0606  7 2 1  355 1841  744
#> 14 1162.7850  8 0 2  860   41 2760
#> 15  898.3652  6 2 2  148  753  951
#> 20 1268.8022  8 2 0  975 2645  124

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.9   1.0000000 0.9473684   1.000 0.3177634 0.6322931
#> 3  Site1 Site3     0.8   1.0000000 0.8888889   1.000 0.2087912 0.2320217
#> 4  Site1 Site4     1.0   1.0000000 1.0000000   1.000 0.2033509 0.6010855
#> 5  Site1 Site5     0.8   1.0000000 0.8888889   1.000 0.1013072 0.1261872
#> 8  Site2 Site3     0.7   0.7777778 0.8235294   0.875 0.1330320 0.2286349
#> 9  Site2 Site4     0.9   1.0000000 0.9473684   1.000 0.3985557 0.5277778
#> 10 Site2 Site5     0.7   0.7777778 0.8235294   0.875 0.2154780 0.3230209
#> 14 Site3 Site4     0.8   1.0000000 0.8888889   1.000 0.3804468 0.9544950
#> 15 Site3 Site5     0.6   0.6000000 0.7500000   0.750 0.1480000 0.1642619
#> 20 Site4 Site5     0.8   1.0000000 0.8888889   1.000 0.4132231 0.8871702
#>       Euclidean  a b c    A    B    C
#> 2  0.0011441348  9 1 0  466  271 1730
#> 3  0.0014929154  8 2 0  171  566  730
#> 4  0.0006782643 10 0 0  443  294 3177
#> 5  0.0011798409  8 2 0   93  644 1006
#> 8  0.0008265610  7 2 1  206 1990  695
#> 9  0.0006831056  9 0 1 1159 1037 2461
#> 10 0.0008018857  7 2 1  355 1841  744
#> 14 0.0008592652  8 0 2  860   41 2760
#> 15 0.0011118954  6 2 2  148  753  951
#> 20 0.0007875242  8 2 0  975 2645  124