Skip to contents

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

Usage

similarity_to_dissimilarity(similarity, include_formula = TRUE)

Arguments

similarity

The output object from similarity() or dissimilarity_to_similarity().

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 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 similarity

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

dissimilarity = 1 - similarity

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: dissimilarity similarity_to_dissimilarity

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)

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.8000000   0.8000000 0.8888889 0.8888889 0.1899736 0.2087821
#> 3  Site1 Site3 0.8000000   0.8000000 0.8888889 0.8888889 0.1294212 0.1333886
#> 4  Site1 Site4 0.7000000   0.7777778 0.8235294 0.8750000 0.1335138 0.1465347
#> 5  Site1 Site5 0.9000000   1.0000000 0.9473684 1.0000000 0.3795672 0.4432477
#> 8  Site2 Site3 0.8000000   0.8000000 0.8888889 0.8888889 0.1613495 0.1717408
#> 9  Site2 Site4 0.8888889   1.0000000 0.9411765 1.0000000 0.3346906 0.4069307
#> 10 Site2 Site5 0.9000000   1.0000000 0.9473684 1.0000000 0.1085677 0.1147994
#> 14 Site3 Site4 0.7000000   0.7777778 0.8235294 0.8750000 0.2994326 0.3396040
#> 15 Site3 Site5 0.9000000   1.0000000 0.9473684 1.0000000 0.2239889 0.2529274
#> 20 Site4 Site5 0.8000000   1.0000000 0.8888889 1.0000000 0.1723875 0.2237624
#>       Euclidean a b c   A    B    C
#> 2  0.0008196407 8 1 1 252  955 1194
#> 3  0.0009249688 8 1 1 161 1046 1120
#> 4  0.0009060300 7 2 1 148 1059  862
#> 5  0.0009905647 9 0 1 535  672 1077
#> 8  0.0009923735 8 1 1 220 1226 1061
#> 9  0.0012447619 8 1 0 411 1035  599
#> 10 0.0007898576 9 0 1 166 1280 1446
#> 14 0.0014155492 7 2 1 343  938  667
#> 15 0.0008993141 9 0 1 324  957 1288
#> 20 0.0009239913 8 0 2 226  784 1386

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.2000000   0.2000000 0.11111111 0.1111111 0.8100264 0.7912179
#> 3  Site1 Site3 0.2000000   0.2000000 0.11111111 0.1111111 0.8705788 0.8666114
#> 4  Site1 Site4 0.3000000   0.2222222 0.17647059 0.1250000 0.8664862 0.8534653
#> 5  Site1 Site5 0.1000000   0.0000000 0.05263158 0.0000000 0.6204328 0.5567523
#> 8  Site2 Site3 0.2000000   0.2000000 0.11111111 0.1111111 0.8386505 0.8282592
#> 9  Site2 Site4 0.1111111   0.0000000 0.05882353 0.0000000 0.6653094 0.5930693
#> 10 Site2 Site5 0.1000000   0.0000000 0.05263158 0.0000000 0.8914323 0.8852006
#> 14 Site3 Site4 0.3000000   0.2222222 0.17647059 0.1250000 0.7005674 0.6603960
#> 15 Site3 Site5 0.1000000   0.0000000 0.05263158 0.0000000 0.7760111 0.7470726
#> 20 Site4 Site5 0.2000000   0.0000000 0.11111111 0.0000000 0.8276125 0.7762376
#>    Euclidean a b c   A    B    C
#> 2  1219.0468 8 1 1 252  955 1194
#> 3  1080.1176 8 1 1 161 1046 1120
#> 4  1102.7162 7 2 1 148 1059  862
#> 5  1008.5252 9 0 1 535  672 1077
#> 8  1006.6852 8 1 1 220 1226 1061
#> 9   802.3665 8 1 0 411 1035  599
#> 10 1265.0510 9 0 1 166 1280 1446
#> 14  705.4396 7 2 1 343  938  667
#> 15 1110.9586 9 0 1 324  957 1288
#> 20 1081.2613 8 0 2 226  784 1386