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)
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.2000000   0.0000000 0.11111111 0.0000000 0.6404855 0.5799893
#> 3  Site1 Site3 0.3000000   0.2222222 0.17647059 0.1250000 0.4874931 0.1618182
#> 4  Site1 Site4 0.1111111   0.0000000 0.05882353 0.0000000 0.6908825 0.6047382
#> 5  Site1 Site5 0.3000000   0.2222222 0.17647059 0.1250000 0.7916129 0.4634551
#> 8  Site2 Site3 0.1000000   0.0000000 0.05263158 0.0000000 0.6685753 0.5527273
#> 9  Site2 Site4 0.1000000   0.0000000 0.05263158 0.0000000 0.4845955 0.4420200
#> 10 Site2 Site5 0.1000000   0.0000000 0.05263158 0.0000000 0.9020639 0.7990033
#> 14 Site3 Site4 0.2000000   0.2000000 0.11111111 0.1111111 0.7544379 0.6981818
#> 15 Site3 Site5 0.2000000   0.2000000 0.11111111 0.1111111 0.6427732 0.4950166
#> 20 Site4 Site5 0.2000000   0.2000000 0.11111111 0.1111111 0.8821396 0.7840532
#>    Euclidean a b c   A    B    C
#> 2  1145.6845 8 0 2 785 1713 1084
#> 3  1021.9335 7 1 2 922 1576  178
#> 4  1219.3958 8 0 1 634 1864  970
#> 5  1258.6906 7 1 2 323 2175  279
#> 8   861.1231 9 1 0 492 1377  608
#> 9   807.3543 9 1 0 895  974  709
#> 10  941.3071 9 1 0 121 1748  481
#> 14  897.8764 8 1 1 332  768 1272
#> 15  502.0299 8 1 1 304  796  298
#> 20  910.9874 8 1 1 130 1474  472

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.8000000   1.0000000 0.8888889 1.0000000 0.35951454 0.4200107
#> 3  Site1 Site3 0.7000000   0.7777778 0.8235294 0.8750000 0.51250695 0.8381818
#> 4  Site1 Site4 0.8888889   1.0000000 0.9411765 1.0000000 0.30911750 0.3952618
#> 5  Site1 Site5 0.7000000   0.7777778 0.8235294 0.8750000 0.20838710 0.5365449
#> 8  Site2 Site3 0.9000000   1.0000000 0.9473684 1.0000000 0.33142472 0.4472727
#> 9  Site2 Site4 0.9000000   1.0000000 0.9473684 1.0000000 0.51540455 0.5579800
#> 10 Site2 Site5 0.9000000   1.0000000 0.9473684 1.0000000 0.09793606 0.2009967
#> 14 Site3 Site4 0.8000000   0.8000000 0.8888889 0.8888889 0.24556213 0.3018182
#> 15 Site3 Site5 0.8000000   0.8000000 0.8888889 0.8888889 0.35722679 0.5049834
#> 20 Site4 Site5 0.8000000   0.8000000 0.8888889 0.8888889 0.11786038 0.2159468
#>       Euclidean a b c   A    B    C
#> 2  0.0008720795 8 0 2 785 1713 1084
#> 3  0.0009775807 7 1 2 922 1576  178
#> 4  0.0008194063 8 0 1 634 1864  970
#> 5  0.0007938457 7 1 2 323 2175  279
#> 8  0.0011599272 9 1 0 492 1377  608
#> 9  0.0012370813 9 1 0 895  974  709
#> 10 0.0010612252 9 1 0 121 1748  481
#> 14 0.0011125000 8 1 1 332  768 1272
#> 15 0.0019879535 8 1 1 304  796  298
#> 20 0.0010965064 8 1 1 130 1474  472