Skip to contents

Converts a (dis)similarity matrix or a list of such matrices into a bioregion.pairwise.metric object compatible with the bioregion package. The input can come from base R, dist objects, or outputs from other packages.

Usage

as_bioregion_pairwise(
  mat,
  metric_name = NULL,
  pkg = NULL,
  is_similarity = FALSE
)

Arguments

mat

A matrix, a dist object, or a list of these representing pairwise similarity or dissimilarity values to convert into a bioregion.pairwise.metric object. This function can also directly handle outputs from other R packages (see the pkg argument).

metric_name

Optional character vector or single character string specifying the name of the (dis)similarity metric(s), which will appear as column names in the output (see Note).

pkg

An optional character string indicating the name of the package from which mat was generated (NULL by default, see Details). Available options are "adespatial", "betapart", "ecodist", or "vegan".

is_similarity

A logical value indicating whether the input data represents similarity (TRUE) or dissimilarity (FALSE).

Value

A dissimilarity or similarity object of class bioregion.pairwise.metric, compatible with the bioregion package.

Details

This function can directly handle outputs from ten functions across four packages:

See the documentation of these packages for more information:

  • https://cran.r-project.org/package=adespatial

  • https://cran.r-project.org/package=betapart

  • https://cran.r-project.org/package=ecodist

  • https://cran.r-project.org/package=vegan

Note

If no specific package is specified (i.e., pkg = NULL), site names will be based on the row names of the first matrix. If row names are NULL, they will be generated automatically. If mat is a named list, those names will be used as column names only if metric_name = NULL.

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

Author

Maxime Lenormand (maxime.lenormand@inrae.fr)
Boris Leroy (leroy.boris@gmail.com)
Pierre Denelle (pierre.denelle@gmail.com)

Examples


mat <- matrix(runif(100), 10, 10)
rownames(mat) <- paste0("s",1:10)

pair <- as_bioregion_pairwise(list(mat,mat,mat), 
                              metric_name = NULL,
                              pkg = NULL,
                              is_similarity = FALSE)
                              
pair
#> Data.frame of dissimilarity between sites
#>  - Total number of sites:  10 
#>  - Total number of species:  NA 
#>  - Number of rows:  45 
#>  - Number of dissimilarity metrics:  3 
#> 
#> 
#>    Site1 Site2    Metric1    Metric2    Metric3
#> 2     s1    s2 0.87460066 0.87460066 0.87460066
#> 3     s1    s3 0.28989230 0.28989230 0.28989230
#> 4     s1    s4 0.03123033 0.03123033 0.03123033
#> 5     s1    s5 0.68016292 0.68016292 0.68016292
#> 6     s1    s6 0.46118646 0.46118646 0.46118646
#> 7     s1    s7 0.82519942 0.82519942 0.82519942
#> 8     s1    s8 0.44670247 0.44670247 0.44670247
#> 9     s1    s9 0.52791704 0.52791704 0.52791704
#> 10    s1   s10 0.99706914 0.99706914 0.99706914
#> 13    s2    s3 0.67838043 0.67838043 0.67838043
#> 14    s2    s4 0.22556253 0.22556253 0.22556253
#> 15    s2    s5 0.49884561 0.49884561 0.49884561
#> 16    s2    s6 0.31524175 0.31524175 0.31524175
#> 17    s2    s7 0.27381825 0.27381825 0.27381825
#> 18    s2    s8 0.37151118 0.37151118 0.37151118
#> 19    s2    s9 0.60063752 0.60063752 0.60063752
#> 20    s2   s10 0.14903547 0.14903547 0.14903547
#> 24    s3    s4 0.30083081 0.30083081 0.30083081
#> 25    s3    s5 0.64167935 0.64167935 0.64167935
#> 26    s3    s6 0.17467589 0.17467589 0.17467589
#> 27    s3    s7 0.57004495 0.57004495 0.57004495
#> 28    s3    s8 0.02806097 0.02806097 0.02806097
#> 29    s3    s9 0.26137136 0.26137136 0.26137136
#> 30    s3   s10 0.51855664 0.51855664 0.51855664
#> 35    s4    s5 0.66028435 0.66028435 0.66028435
#> 36    s4    s6 0.53157354 0.53157354 0.53157354
#> 37    s4    s7 0.33571908 0.33571908 0.33571908
#> 38    s4    s8 0.46598719 0.46598719 0.46598719
#> 39    s4    s9 0.29005016 0.29005016 0.29005016
#> 40    s4   s10 0.84612005 0.84612005 0.84612005
#> 46    s5    s6 0.49363702 0.49363702 0.49363702
#> 47    s5    s7 0.59626279 0.59626279 0.59626279
#> 48    s5    s8 0.39003139 0.39003139 0.39003139
#> 49    s5    s9 0.48007517 0.48007517 0.48007517
#> 50    s5   s10 0.71826972 0.71826972 0.71826972
#> 57    s6    s7 0.19151803 0.19151803 0.19151803
#> 58    s6    s8 0.02006522 0.02006522 0.02006522
#> 59    s6    s9 0.92000555 0.92000555 0.92000555
#> 60    s6   s10 0.24131402 0.24131402 0.24131402
#> 68    s7    s8 0.37697093 0.37697093 0.37697093
#> 69    s7    s9 0.40072018 0.40072018 0.40072018
#> 70    s7   s10 0.54704337 0.54704337 0.54704337
#> 79    s8    s9 0.21317271 0.21317271 0.21317271
#> 80    s8   s10 0.83480182 0.83480182 0.83480182
#> 90    s9   s10 0.02795603 0.02795603 0.02795603