forked from FRBCesab/workshop-free
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.json
59 lines (59 loc) · 92.8 KB
/
search.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
"articles": [
{
"path": "courses.html",
"title": "Courses",
"author": [],
"contents": "\n\nComing soon…\nCorrections\nIf you see mistakes or want to suggest changes, please Create an issue on the source repository.\nReuse\nThe material of this website is licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/frbcesab/workshop-free/.\nCitation\nCasajus N, Grénié M, Magneville C & Villéger S (2022) Workshop FRB-CESAB & FREE Working Group: Functional Rarity and Diversity in Ecology.\n\n\n\n",
"last_modified": "2022-06-15T10:13:17+00:00"
},
{
"path": "index.html",
"title": "Functional Rarity and Diversity in Ecology",
"description": "FRB-CESAB & FREE Working Group Workshop",
"author": [
{
"name": "Nicolas Casajus",
"url": "https://nicolascasajus.fr"
},
{
"name": "Matthias Grénié",
"url": "https://rekyt.github.io/"
},
{
"name": "Camille Magneville",
"url": "https://umr-marbec.fr/membre/camille-magneville/"
},
{
"name": "Sébastien Villéger",
"url": "https://umr-marbec.fr/membre/sebastien-villeger/"
}
],
"date": "`r format(Sys.Date(), '%m-%d-%Y')`",
"contents": "\n\n\nThe objective of this workshop, co-organized by the FRB-CESAB and the working group FREE is to give a general introduction to functional ecology. During the practice session, participants will learn to calculate various functional rarity and diversity index.\n\nProgram\n08:30 – 09:00\n Welcome coffee and icebreaker\n09:00 – 12:30\n General introduction (traits, distance metrics, functional space) (~ 45 min) Break and questions (~ 15 min) Practice using the R packages mFD and funrar (~ 2h30)\n12:30 – 14:00\n Lunch break\n14:00 – 18:00\n Conference - More info here\n\nPrerequisites\nPlease follow this tutorial to correctly install your working environment (R, RStudio, git, etc.).\nCorrections\nIf you see mistakes or want to suggest changes, please Create an issue on the source repository.\nReuse\nThe material of this website is licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/frbcesab/workshop-free/.\nCitation\nCasajus N, Grénié M, Magneville C & Villéger S (2022) Workshop FRB-CESAB & FREE Working Group: Functional Rarity and Diversity in Ecology.\n\n\n\n",
"last_modified": "2022-06-15T10:13:18+00:00"
},
{
"path": "instructions.html",
"title": "Installation of R, RStudio and git",
"author": [],
"contents": "\n\nContents\nInstallation Windows\n macOS\n Ubuntu\n\nConfigurationgit\n GitHub SSH keys\n GitHub PAT\n\nFor the workshop\nCorrections\nReuse\nCitation\n\n\n Please install the latest versions of RStudio, and git.\n\nInstallation\n Windows\nDownload at:https://cran.r-project.org/\n Click on Download R for Windows Click on base Click on Download R 4.2.0 for Windows Open R-4.2.0-win.exe and follow instructions\n\nDownload RStudio Desktop at:https://www.rstudio.com/products/rstudio/download/#download\n Download the version for Windows 10/11 (the .exe and not the .zip) Open RStudio-2022.02.3-492.exe and follow instructions Check if RStudio has found . Launch RStudio and run:\n\n\nR.version.string\n## [1] \"R version 4.2.0 (2022-04-22)\"\n\n\n\n\nDownload git at:https://git-scm.com/downloads\n Download the 64-bit version for Windows Open Git-2.36.1-64-bit.exe and follow instructions Check if RStudio has found git. Launch RStudio and run:\n\n\nSys.which(\"git\")\n## C:/Program Files/Git/bin/git.exe\n\n\n\n\nDownload Rtools4.2 at:https://cran.r-project.org/bin/windows/Rtools/rtools42/rtools.html\n Download the 64-bit version for Windows Open rtools42-5253-5107 and follow instructions\nThe installation of Rtools4.2 is optional, but this software is required to install packages (from sources) containing compiled code (C/C++/Fortran). Rtools4.2 contains in particular the utility make.\nRestart RStudio and check that find the utility make:\n\n\nSys.which(\"make\")\n## \"C:/rtools42/usr/bin/make.exe\"\n\n\n\nNow you can install packages from sources:\n\n\ninstall.packages(\"jsonlite\", type = \"source\")\n\n\n\n\nInstall pandoc (optional)\nThe package rmarkdown requires the software pandoc to convert document from one format (e.g. .Rmd) to another (e.g. .html).\nDownload the latest version of pandoc at: https://github.com/jgm/pandoc/releases, and follow instructions.\n\nInstall a LaTeX distribution (optional)\nIf you want to convert documents from .Rmd to .pdf, you will need LaTeX. You can install a lightened distribution using the package tinytex. Open RStudio and run:\n\n\n## Install tinytex ----\ninstall.packages(\"tinytex\")\n\n## Install LaTeX ----\ntinytex::install_tinytex()\n\n\n\nN.B. If you already have a LaTeX distribution, do not install tinytex.\n\n macOS\nTh easiest way to set up your environment is by using the package manager for macOS Homebrew. With this tool you can install (and update) your software directly from the terminal. First you need to install the Apple software Command Line Tools for Xcode.\nOpen a terminal, run this line and accept the license:\n## Install Xcode Command Line Tools ----\nsudo xcode-select --install\nThen you can install Homebrew:\n## Install Homebrew ----\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"\n\n## Check installation ----\nbrew --version\n## Homebrew 3.5.1-24-ga3d14ff\n\n## Update repositories (list of available software) ----\nbrew update\nFollow these lines to install your environment:\n## Install utilities for R ----\nbrew install --cask xquartz ## Graphical window system\nbrew install gfortran ## FORTRAN compiler for GCC\n\n## Install R ----\nbrew install --cask r\n\n## Install RStudio Desktop ----\nbrew install --cask rstudio\n\n## Install git ----\nbrew install git\n\n## Install pandoc ----\nbrew install pandoc ## Convert documents (Rmd, html, etc.)\nOpen RStudio and check your installation:\n\n\nR.version.string\n## \"R version 4.2.0 (2022-04-22)\"\n\nSys.which(\"git\")\n## git\n## \"/usr/bin/git\"\n\nSys.which(\"make\")\n## make \n## \"/usr/bin/make\"\n\nSys.which(\"pandoc\")\n## pandoc \n## \"/usr/local/bin/pandoc\"\n\n\n\n\nIf you want to convert documents from .Rmd to .pdf, you will need LaTeX. You can install a lightened distribution using the package tinytex. Open RStudio and run:\n\n\n## Install tinytex ----\ninstall.packages(\"tinytex\")\n\n## Install LaTeX ----\ntinytex::install_tinytex()\n\n\n\n\n Congrats! You have successfully install your environment. The following commands will install system libraries (software) required by some packages (sf, sp, rgdal, rgeos, raster, terra, xml, etc.).\n## Install other utilities for R (spatial and others) ----\nbrew install libgit2 \nbrew install libxml2 \nbrew install poppler \nbrew install geos gdal netcdf proj udunits\nTo keep your system up-to-date, run regularly:\n## Update environment ----\nbrew update && brew upgrade --greedy\n\n Ubuntu\nFirst check your version of Ubuntu in a terminal:\n## Check Ubuntu version ----\ncat /etc/issue\n## Ubuntu 22.04 LTS\n\nTable 1. List of CRAN repositories for different versions of Ubuntu\nRelease\nRelease name\nRepository URL\n22.04 LTS\nJammy Jellyfish\nhttps://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/\n21.10\nImpish Indri\nhttps://cloud.r-project.org/bin/linux/ubuntu impish-cran40/\n21.04\nHirsute Hippo\nhttps://cloud.r-project.org/bin/linux/ubuntu hirsute-cran40/\n20.04 LTS\nFocal Fossa\nhttps://cloud.r-project.org/bin/linux/ubuntu focal-cran40/\n18.04 LTS\nBionic Beaver\nhttps://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/\n16.04 LTS\nXenial Xerus\nhttps://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/\n\nInstall by following these steps (change the URL below by the one specific to your version of Ubuntu, cf. Table 1) :\n## Install APT utilities ----\nsudo apt install software-properties-common\n\n## Add CRAN GPG key ----\nsudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9\n\n## Add CRAN repository to APT repositories list ----\nsudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/'\n\n## Update packages list ----\nsudo apt update\n\n## Install R ----\nsudo apt install r-base\n\n## Install R (for development, recommended) ----\nsudo apt install build-essential\nsudo apt install r-base-dev\n\nTo install RStudio Desktop visit this page: https://www.rstudio.com/products/rstudio/download/#download, download the .deb file for Ubuntu 18+/Debian 10+ and install it. If you have an older version of Ubuntu (16.04), visit this page: https://www.rstudio.com/products/rstudio/older-versions/\nAlternatively, you can install RStudio Desktop from the terminal:\n## Install wget utility ----\nsudo apt install wget\n\n## Download RStudio Desktop installer (Ubuntu 22.04) ----\nwget https://download1.rstudio.org/desktop/jammy/amd64/rstudio-2022.02.3-492-amd64.deb\n\n## Download RStudio Desktop installer (Ubuntu >= 18.04) ----\n# wget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-2022.02.1-461-amd64.deb\n\n## Download RStudio Desktop installer (Ubuntu 16.04 only) ----\n# wget https://download1.rstudio.org/desktop/xenial/amd64/rstudio-1.4.1106-amd64.deb\n\n## Install RStudio Desktop ----\nsudo dpkg -i rstudio-2022.02.3-492-amd64.deb\n# sudo dpkg -i rstudio-2022.02.1-461-amd64.deb\n# sudo dpkg -i rstudio-1.4.1106-amd64.deb\n\n## Remove installer ----\nrm rstudio-2022.02.3-492-amd64.deb\n# rm rstudio-2022.02.1-461-amd64.deb\n# rm rstudio-1.4.1106-amd64.deb\n\nNow let’s install git:\nsudo apt install git\nFinally, install pandoc (to convert documents using rmarkdown):\nsudo apt install pandoc\n\nOpen RStudio and check your installation:\n\n\nR.version.string\n## \"R version 4.2.0 (2022-04-22)\"\n\nSys.which(\"git\")\n## git\n## \"/usr/bin/git\"\n\nSys.which(\"make\")\n## make \n## \"/usr/bin/make\"\n\nSys.which(\"pandoc\")\n## pandoc \n## \"/usr/bin/pandoc\"\n\n\n\n\nIf you want to convert documents from .Rmd to .pdf, you will need LaTeX. You can install a lightened distribution using the package tinytex. Open RStudio and run:\n\n\n## Install tinytex ----\ninstall.packages(\"tinytex\")\n\n## Install LaTeX ----\ntinytex::install_tinytex()\n\n\n\n\n Congrats! You have successfully install your environment. The following commands will install system libraries (software) required by some packages (sf, sp, rgdal, rgeos, raster, terra, xml, etc.).\n## Install other utilities for R (spatial and others) ----\nsudo apt install libgdal-dev libproj-dev libgeos-dev libudunits2-dev libnetcdf-dev\nsudo apt install libcairo2-dev libmagick++-dev\nsudo apt install libpoppler-cpp-dev\nTo keep your system up-to-date, do not forget to frequently run:\n## Update system ----\nsudo apt update && sudo apt upgrade\n\nConfiguration\ngit\nTo use git, you need to store your credentials (user name and email) that will be added to all your commits. Open a terminal (you can use the terminal of RStudio) and run:\ngit config --global user.name \"Jane Doe\"\ngit config --global user.email \"jane.doe@mail.com\"\nWhen you create a new git project the default branch will be named master. It’s recommended to replace master by main (for more information read this article).\nOn a terminal, run:\ngit config --global init.defaultBranch \"main\"\nFrom now when you will initialize git in a new project the default branch will be main.\n\n GitHub SSH keys\nTo communicate with GitHub, you can use the protocol HTTPS (default) or the protocol SSH (recommended). The protocol SSH is a more secure method of logging into a remote server (GitHub). To use this protocol, you need to generate an SSH keys pair that consists in creating two long strings of characters: a public key and a private key. You can place the public key on any server (for instance GitHub), and then connect to the server using a device (your laptop) that has access to the private key.\nTo generate a new SSH keys pair proceed as follow:\n Create an account on GitHub at https://github.com/signup (if not already done) Open RStudio and click on: Tools > Global options > Git/SVN Click on Create RSA Key and then click on Create (you can omit the passphrase). This new SSH keys pair has been stored in ~/.ssh/. Click on View public key and copy it Go to the page https://github.com/settings/keys and click on New SSH key Choose a name for your key (e.g. your laptop name) and paste your public key Finally click on Add SSH key\n\n If you are on Ubuntu you need to install the following utility:\nsudo apt install ssh-askpass\n\nLet’s test the SSH connection to GitHub. Open a terminal and run (you need to accept the fingerprint, just enter yes):\nssh -T git@github.com\nCongrats! You can now communicate with GitHub using the SSH protocol.\n\n From now, you need to use the SSH URL when connecting a new GitHub project (named remote).\n## URL HTTPS ----\nhttps://github.com/frbcesab/workshop-free.git\n\n## URL SSH (use this one) ----\ngit@github.com:frbcesab/workshop-free.git\n\n If you lose your private SSH key you won’t be able to establish a connection with GitHub. You’ll need to delete your SSH key on GitHub and to create a new one.\n\n GitHub PAT\nIf you want to use the GitHub API, essentially with the package usethis, you need to create a GitHub Personal Access Token (PAT).\nGo to https://github.com/settings/tokens\n Click on Generate new token Choose a name for your new token (e.g. your laptop name) In the section scopes, select at least repo and workflow Copy this token.\nThen open RStudio and run:\n\n\n## Install usethis package ----\ninstall.packages(\"usethis\")\n\n## Open ~/.Renviron file ----\nusethis::edit_r_environ()\n## • Modify '~/.Renviron'\n## • Restart R for changes to take effect\n\n\n\nIn the ~/.Renviron file, add this new line: GITHUB_PAT='XXX' where XXX is your token. Do not forget to restart .\n\nFinally let’s tell usethis to use the SSH protocol. Open RStudio and run:\n\n\n## Open ~/.Rprofile file ----\nusethis::edit_r_profile()\n## • Modify '~/.Rprofile'\n## • Restart R for changes to take effect\n\n\n\nIn the ~/.Rprofile file, add this new line: options(usethis.protocol = \"ssh\"). Do not forget to restart .\n\nFor the workshop\nYou will need to install the following R packages:\n\n\n## CRAN packages ----\npkgs <- c(\"funrar\", \"mFD\")\ninstall.packages(pkgs)\n\n\n\n\nIn addition, you must download a copy of the content of the workshop. We recommend that you create a copy (fork) of the GitHub repository of the workshop on your GitHub space. Then, using RStudio you will clone (download) your fork.\nGo to the GitHub URL of the workshop repository: https://github.com/frbcesab/workshop-free. Then follow these instructions to fork the repository.\n Fork the repository (1) Fork the repository (2) Get the SSH URL of your fork (1) Get the SSH URL of your fork (2)Then open RStudio Desktop and follow these instructions to create a new project from your GitHub repository (fork of the original repository)\n Clone your fork (1) Clone your fork (2) Clone your fork (3)Congrats! You have your own copy of the workshop content (data, instructions and courses). If you want you can use git to commit changes during the workshop and send these modifications to your GitHub repository.\nCorrections\nIf you see mistakes or want to suggest changes, please Create an issue on the source repository.\nReuse\nThe material of this website is licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/frbcesab/workshop-free/.\nCitation\nCasajus N, Grénié M, Magneville C & Villéger S (2022) Workshop FRB-CESAB & FREE Working Group: Functional Rarity and Diversity in Ecology.\n\n\n\n",
"last_modified": "2022-06-15T10:13:19+00:00"
},
{
"path": "practice.html",
"title": "Practice",
"author": [],
"contents": "\n\nContents\nAbout\nPrerequisites\nData description\nQuestions\nPart 1. Build a functional space using the mFD package1.0. Compute summaries about your data\n1.1. What about the traits?\n1.2. Computing distances between species based on functional traits\n1.3. Building functional spaces and chosing the best one1.3.1. Computing several multimensional functional spaces and assessing their quality\n1.3.2. Illustrating the quality of the functional spaces\n1.3.3. Testing the correlation between functional axes and traits\n\n1.4. Plotting the selected functional space and position of species\n\nPart 2. Computing and plotting FD indices using the mFD package2.1. Computing and plotting alpha FD indices\n2.2. Computing and plotting beta FD indices\n\nPart 3. Functional rarity3.1 Components of functional rarity: trait originality and rarity\n3.2 Different indices of functional originality\n3.3 Computing functional originality3.3.1 At regional scale\n3.3.2 At local scale\n\n3.4 Plotting functional originality\n\n\nAbout\n\nThis tutorial describes the basic workflow showing how to compute step by step functional diversity (FD) indices in a multidimensional space. It is divided in three parts:\nComputing trait-based distances and the multidimensional functional space\nUsing the mFD package to compute FD alpha and beta indices and plot them (Magneville et al. 2021)\nUsing the funrar package to compute functional rarity indices (Violle et al. 2017, Grenié et al. 2017)\n\nN.B. You can chose to do Part 2 and Part 3 in the order that you want but Part 1 has to be realized first.\n\nPrerequisites\nBe sure you have followed the instructions to set up your system (e.g. R version >= 3.5).\nIf not already done, please install the following R packages:\n\n\n## CRAN packages ----\npkgs <- c(\"funrar\", \"mFD\")\ninstall.packages(pkgs)\n\n\n\n\nData description\nThe dataset used as study case all along this workshop is the Fruits dataset based on 25 types of fruits (i.e. species) distributed in 10 fruits baskets (i.e. assemblages). Each fruit is characterized by five traits values summarized in the following table:\n\nTrait name\nTrait measurement\nTrait type\nNumber of classes\nClasses code\nUnit\nSize\nMaximal diameter\nOrdinal\n5\n0-1 ; 1-3 ; 3-5 ; 5-10 ; 10-20\ncm\nPlant\nGrowth form\nCategorical\n4\ntree ; shrub ; vine ; forb\nNA\nClimate\nClimatic niche\nOrdinal\n3\ntemperate ; subtropical ; tropical\nNA\nSeed\nSeed type\nOrdinal\n3\nnone ; pip ; pit\nNA\nSugar\nSugar\nContinuous\nNA\nNA\ng/kg\n\nThe use of the mFD and funrar packages is based on two datasets:\na data.frame summarizing traits values for each species called fruits_traits in this tutorial\nCode\n\n\n## Loading data ----\ndata(\"fruits_traits\", package = \"mFD\")\n\n## Removing fuzzy traits in this tutorial ----\nfruits_traits <- fruits_traits[ , -c(6:8)]\n\n## Display the table ----\nknitr::kable(head(fruits_traits),\n caption = \"Species x traits data.frame\")\n\n\nTable 1: Species x traits data.frame\n\nSize\nPlant\nClimate\nSeed\nSugar\napple\n5-10cm\ntree\ntemperate\npip\n103.9\napricot\n3-5cm\ntree\ntemperate\npit\n92.4\nbanana\n10-20cm\ntree\ntropical\nnone\n122.3\ncurrant\n0-1cm\nshrub\ntemperate\npip\n73.7\nblackberry\n1-3cm\nshrub\ntemperate\npip\n48.8\nblueberry\n0-1cm\nforb\ntemperate\npip\n100.0\n\n\na matrix summarizing species assemblages called baskets_fruits_weights in this tutorial. Weights in this matrix can be occurrence data, abundance, biomass, coverage, etc. The studied example works with biomass (i.e. grams of a fruit in a basket) and this matrix looks as follows:\nCode\n\n\n## Loading data ----\ndata(\"baskets_fruits_weights\", package = \"mFD\")\n\n## Display the table ----\nknitr::kable(as.data.frame(baskets_fruits_weights[1:6, 1:6]), \n centering = TRUE,\n caption = \"Species x assemblages matrix based on the **fruits** dataset\")\n\n\nTable 2: Species x assemblages matrix based on the fruits dataset\n\napple\napricot\nbanana\ncurrant\nblackberry\nblueberry\nbasket_1\n400\n0\n100\n0\n0\n0\nbasket_2\n200\n0\n400\n0\n0\n0\nbasket_3\n200\n0\n500\n0\n0\n0\nbasket_4\n300\n0\n0\n0\n0\n0\nbasket_5\n200\n0\n0\n0\n0\n0\nbasket_6\n100\n0\n200\n0\n0\n0\n\nQuestions\nUsing this Practice, we ask the following questions:\nHow different are the fruits baskets based on their functional traits?\n{{ Question functional rarity }}\n{{ Question funbiogeo }}\nTo answer these three questions, the first step is to build a functional space based on species traits on which functional diversity and functional rarity indices will be then computed.\n\nPart 1. Build a functional space using the mFD package\n\n1.0. Compute summaries about your data\n\nThis part is not developed in this Practice (not enough time to see everything ;) ), but it could be useful to know that the mFD package can compute summaries about your traits or assemblage data. For instance, you can compute a matrix of species occurrence in each assemblage (needed in 2.2).\n\n\n## Summary of the assemblages * species data.frame ----\nasb_sp_fruits_summ <- mFD::asb.sp.summary(asb_sp_w = baskets_fruits_weights)\nasb_sp_fruits_occ <- asb_sp_fruits_summ$\"asb_sp_occ\"\n\nhead(asb_sp_fruits_occ)\n\n\n apple apricot banana currant blackberry blueberry cherry\nbasket_1 1 0 1 0 0 0 1\nbasket_2 1 0 1 0 0 0 1\nbasket_3 1 0 1 0 0 0 1\nbasket_4 1 0 0 0 0 0 0\nbasket_5 1 0 0 0 0 0 0\nbasket_6 1 0 1 0 0 0 0\n grape grapefruit kiwifruit lemon lime litchi mango melon\nbasket_1 0 0 0 1 0 0 0 1\nbasket_2 0 0 0 1 0 0 0 1\nbasket_3 0 0 0 1 0 0 0 1\nbasket_4 0 0 1 1 0 0 0 0\nbasket_5 0 0 1 1 0 0 0 0\nbasket_6 0 0 0 0 1 1 1 0\n orange passion_fruit peach pear pineapple plum raspberry\nbasket_1 0 1 0 1 0 0 0\nbasket_2 0 1 0 1 0 0 0\nbasket_3 0 1 0 1 0 0 0\nbasket_4 1 0 1 1 0 1 0\nbasket_5 1 0 1 1 0 1 0\nbasket_6 1 0 0 0 1 0 0\n strawberry tangerine water_melon\nbasket_1 1 0 0\nbasket_2 1 0 0\nbasket_3 1 0 0\nbasket_4 0 1 0\nbasket_5 0 1 0\nbasket_6 0 0 1\n\n\n1.1. What about the traits?\n\nThe first thing to do before starting analyses is to know your data. To do so, you must be able to characterize the traits you are using (i.e. tell the package what type of traits you are using). That is why mFD package needs a data.frame summarizing the type of each trait (i.e. each column of the fruits_traits data.frame).\nCode\n\n\n## Loading data ----\ndata(\"fruits_traits_cat\", package = \"mFD\")\n\n## Removing fuzzy traits in this tutorial ----\nfruits_traits_cat <- fruits_traits_cat[-c(6:8), ]\n\n## Thus remove the \"fuzzy_name\" column ----\nfruits_traits_cat <- fruits_traits_cat[ , -3]\n\n## Displaying the table ----\nknitr::kable(head(fruits_traits_cat), \n caption = \"Traits types based on **fruits & baskets** dataset\")\n\n\nTable 3: Traits types based on fruits & baskets dataset\ntrait_name\ntrait_type\nSize\nO\nPlant\nN\nClimate\nO\nSeed\nO\nSugar\nQ\n\nThe first column contains traits name. The second column contains traits type following this code:\nN: nominal trait (factor variable)\nO: ordinal traits (ordered variable)\nC: circular traits (integer values) (N.B. circular traits can not be used in mFD function used to compute functional distance but ok for summary function and function to group species into Functional Entities)\nQ: quantitative traits (numeric values)\nF: fuzzy traits (described with several values defined in several columns in the fruits_traits data.frame)\n\n1.2. Computing distances between species based on functional traits\n\nThe next step toward the computation of functional diversity indices is to estimate functional traits-based distances between species in order to build the functional space in which indices will be computed.\nTo compute trait-based distances, we will use the mFD::funct.dist() function which includes the following arguments:\nCode\n\n\nsp_dist_fruits <- mFD::funct.dist(\n sp_tr = fruits_traits,\n tr_cat = fruits_traits_cat,\n metric = \"gower\",\n scale_euclid = \"scale_center\",\n ordinal_var = \"classic\",\n weight_type = \"equal\",\n stop_if_NA = TRUE)\n\n\n\nsp_tr is the species x trait data.frame\ntr_cat is the data.frame summarizing trait type for each trait\nmetric is a character string referring to the metric used to compute distances. Two metrics are available and the choice depends on your traits data:\nif all traits are continuous use the Euclidean distance (metric = \"euclidean\") and check the Compute Functional Diversity Indices based on Only Continuous Traits tutorial which explains how to build a multidimensional space from traits through PCA analysis or considering directly each trait as a dimension.\nif you have non-continuous traits use the Gower distance (metric = \"gower\") as this method allows traits weighting. This method can also deal with fuzzy traits.\n\nscale_euclid is a character string referring to the way the user wants to scale euclidean traits. You can either chose to scale by range (range), use the center transformation (center), use the scale transformation (scale), use the scale-center transformation (scale_center) or you can chose not to scale (noscale).\nordinal_var is a character string specifying the method to be used for ordinal variables (i.e. ordered). You can either chose to treat ordinal variables as continuous variables (with \"classic\" option) or to treat ordinal variables as ranks (with metric or podani options, see mFD::funct.dist() help file for detail).\nweight_type is a character string referring to the type of method to weight traits. You can either chose to define weights using the tr_cat data.frame (cf. step 1.1) (user option) or you can chose to give the same weight to all traits (equal option). (N.B. Using mFD, you can not define weights for fuzzy traits, use gawdis package instead)\nstop_if_NA is a logical value to stop or not the process if the sp_tr data.frame contains NA. If the sp_tr data.frame contains NA you can either chose to compute anyway functional distances (but keep in mind that Functional measures are sensitive to missing traits!) or you can delete species with missing or extrapolate missing traits (see Johnson et al. (2020)).\nThis function returns a dist object with traits-based distances between all pairs of species:\nCode\n\n\n## Output of the function mFD::funct.dist() ----\nround(sp_dist_fruits, 3)\n\n\n apple apricot banana currant blackberry blueberry\napricot 0.166 \nbanana 0.375 0.541 \ncurrant 0.391 0.426 0.767 \nblackberry 0.376 0.410 0.751 0.084 \nblueberry 0.355 0.410 0.731 0.236 0.320 \ncherry 0.233 0.099 0.558 0.425 0.409 0.389\ngrape 0.380 0.446 0.705 0.372 0.356 0.336\ngrapefruit 0.192 0.327 0.268 0.501 0.483 0.537\nkiwifruit 0.219 0.353 0.595 0.372 0.356 0.364\nlemon 0.208 0.343 0.384 0.517 0.433 0.553\nlime 0.370 0.404 0.345 0.578 0.494 0.614\nlitchi 0.466 0.332 0.391 0.658 0.642 0.622\nmango 0.395 0.361 0.220 0.786 0.771 0.750\nmelon 0.285 0.419 0.560 0.407 0.391 0.229\norange 0.117 0.251 0.292 0.474 0.459 0.462\npassion_fruit 0.461 0.527 0.414 0.553 0.537 0.516\npeach 0.127 0.062 0.503 0.464 0.448 0.472\npear 0.009 0.157 0.384 0.383 0.367 0.353\npineapple 0.557 0.708 0.233 0.734 0.718 0.502\nplum 0.156 0.009 0.532 0.435 0.419 0.401\nraspberry 0.382 0.416 0.758 0.091 0.007 0.327\nstrawberry 0.376 0.410 0.751 0.284 0.200 0.120\ntangerine 0.153 0.218 0.323 0.444 0.428 0.408\nwater_melon 0.281 0.415 0.556 0.410 0.395 0.226\n cherry grape grapefruit kiwifruit lemon lime litchi\napricot \nbanana \ncurrant \nblackberry \nblueberry \ncherry \ngrape 0.347 \ngrapefruit 0.426 0.573 \nkiwifruit 0.453 0.200 0.373 \nlemon 0.442 0.589 0.116 0.389 \nlime 0.503 0.650 0.277 0.550 0.161 \nlitchi 0.233 0.514 0.459 0.686 0.475 0.336 \nmango 0.362 0.686 0.287 0.614 0.403 0.364 0.172\nmelon 0.518 0.465 0.308 0.266 0.424 0.585 0.751\norange 0.351 0.498 0.075 0.302 0.091 0.252 0.384\npassion_fruit 0.572 0.319 0.453 0.280 0.470 0.331 0.405\npeach 0.161 0.508 0.265 0.308 0.281 0.442 0.394\npear 0.242 0.389 0.184 0.210 0.200 0.361 0.475\npineapple 0.791 0.738 0.435 0.562 0.551 0.512 0.624\nplum 0.090 0.437 0.336 0.363 0.352 0.413 0.323\nraspberry 0.416 0.363 0.490 0.363 0.426 0.487 0.649\nstrawberry 0.409 0.356 0.483 0.356 0.433 0.494 0.642\ntangerine 0.281 0.428 0.145 0.372 0.161 0.222 0.314\nwater_melon 0.515 0.462 0.311 0.262 0.427 0.588 0.748\n mango melon orange passion_fruit peach pear pineapple\napricot \nbanana \ncurrant \nblackberry \nblueberry \ncherry \ngrape \ngrapefruit \nkiwifruit \nlemon \nlime \nlitchi \nmango \nmelon 0.580 \norange 0.312 0.368 \npassion_fruit 0.434 0.546 0.378 \npeach 0.322 0.357 0.210 0.589 \npear 0.404 0.276 0.108 0.470 0.119 \npineapple 0.452 0.327 0.460 0.419 0.670 0.551 \nplum 0.351 0.428 0.261 0.518 0.071 0.152 0.701\nraspberry 0.777 0.398 0.465 0.543 0.455 0.373 0.725\nstrawberry 0.770 0.191 0.458 0.537 0.448 0.367 0.518\ntangerine 0.342 0.437 0.070 0.309 0.280 0.161 0.510\nwater_melon 0.576 0.004 0.364 0.542 0.354 0.272 0.324\n plum raspberry strawberry tangerine\napricot \nbanana \ncurrant \nblackberry \nblueberry \ncherry \ngrape \ngrapefruit \nkiwifruit \nlemon \nlime \nlitchi \nmango \nmelon \norange \npassion_fruit \npeach \npear \npineapple \nplum \nraspberry 0.426 \nstrawberry 0.419 0.207 \ntangerine 0.209 0.435 0.428 \nwater_melon 0.425 0.401 0.194 0.434\n\n\n1.3. Building functional spaces and chosing the best one\n\n1.3.1. Computing several multimensional functional spaces and assessing their quality\n\nIn order to generate a multidimensional space in which functional diversity indices are computed (Mouillot et al. 2013, we will perform a PCoA using the trait-based distances (and if required a functional dendrogram). mFD evaluates the quality of PCoA-based multidimensional spaces according to the deviation between trait-based distances and distances in the functional space (extension of Maire et al. (2015) framework). For that, we will use the mFD::quality.fspaces() function:\n\nCode\n\n\nfspaces_quality_fruits <- mFD::quality.fspaces(\n sp_dist = sp_dist_fruits,\n maxdim_pcoa = 10,\n deviation_weighting = \"absolute\",\n fdist_scaling = FALSE,\n fdendro = \"average\")\n\n\n\nsp_dist is the dist object with pairwise trait-based distance between species as computed in step 1.2\nmaxdim_pcoa is the maximum number of PCoA axes to consider to build multidimensional spaces. Actually, the maximum number of dimensions considered depends on the number of PCoA axes with positive eigenvalues.\ndeviation_weighting refers to the method(s) used to weight the difference between species pairwise distances in the functional space and trait-based distances. You can chose between:\nabsolute: absolute differences are used to compute the mean absolute deviation (mad) . It reflects the actual magnitude of errors that will affect FD metrics.\nsquared: squared differences are used to compute the root of mean square deviation (rmsd). This weighting puts more weight to the large deviations between trait-based distances and distances in the functional space.\nBoth quality metrics can be used with: deviation_weighting = c(\"absolute\", \"squared\").\n\nfdist_scaling specifies whether distances in the functional space should be scaled before computing differences with trait-based distances. Scaling ensures that trait-based distances and distances in the functional space have the same maximum. Scaling distances implies that the quality of the functional space accounts for congruence in distances rather than their equality.\nN.B. The combination of deviation_weighting and fdist_scaling arguments leads to four possible quality metrics: mad, rmsd, mad_scaled and rmsd_scaled\nfdendro specifies the clustering algorithm to compute a functional dendrogram. NULL means no dendrogram computed. The chosen algorithm must be one of the method recognized by the stats::hclust() function from the stats package.\nThis function returns a list various objects:\n\na data.frame gathering for each space (in rows), values of quality metric(s) (in columns)\nCode\n\n\n## Quality metrics of functional spaces ----\nround(fspaces_quality_fruits$\"quality_fspaces\", 3)\n\n\n mad\npcoa_1d 0.150\npcoa_2d 0.073\npcoa_3d 0.047\npcoa_4d 0.040\npcoa_5d 0.049\npcoa_6d 0.055\npcoa_7d 0.060\npcoa_8d 0.064\npcoa_9d 0.065\npcoa_10d 0.065\ntree_average 0.082\n\n\nlist with details required for other tasks in step 1.4 to plot functional space quality and in step 1.5 to plot functional space.\n\nN.B. The space with the best quality has the lowest quality metric. Here, thanks to mad values, we can see that the 4D space is the best one. That is why the following of this Practice will use this multidimensional space.\n\n1.3.2. Illustrating the quality of the functional spaces\n\nWith the mFD package, it is possible to illustrate the quality of PCoA-based multidimensional spaces according to deviation between trait-based distances and distances in the functional space. For that, we use the mFD::quality.fspace.plot() function with the following arguments:\n\nCode\n\n\nmFD::quality.fspaces.plot(\n fspaces_quality = fspaces_quality_fruits,\n quality_metric = \"mad\",\n fspaces_plot = c(\"tree_average\", \"pcoa_2d\", \"pcoa_3d\", \n \"pcoa_4d\", \"pcoa_5d\", \"pcoa_6d\"),\n name_file = NULL,\n range_dist = NULL,\n range_dev = NULL,\n range_qdev = NULL,\n gradient_deviation = c(neg = \"darkblue\", nul = \"grey80\", pos = \"darkred\"),\n gradient_deviation_quality = c(low = \"yellow\", high = \"red\"),\n x_lab = \"Trait-based distance\")\n\n\n\nfspaces_quality is the output of the mFD::quality.fspaces() function (step 1.3.1).\nquality_metric refers to the quality metric used. It should be one of the column name(s) of the table gathering quality metric values (output of mFD::quality.fspaces() called quality_fspaces) (here: fspaces_quality_fruits$quality_fspaces) Thus it can be: mad, rmsd, mad_scaled or rmsd_scaled (see step 1.3.1)\nfspaces_plot refers to the names of spaces for which quality has to be illustrated (up to 10). Names are those used in the output of mFD::quality.fspaces() function showing the values of the quality metric.\nname_file refers to the name of file to save (without extension) if the user wants to save the figure. If the user only wants the plot to be displayed, then name_file = NULL.\nrange_dist, range_dev, range_qdev are arguments to set ranges of panel axes (check function help for further information).\ngradient_deviation and gradient_deviation_quality are arguments to set points colors (check function help for further information).\nxlab is a parameter to set x-axis label.\n\nThis function generates a figure with three panels (in rows) for each selected functional space (in columns). Each column represents a functional space, the value of the quality metric is written on the top of each column. The x-axis of all panels represents trait-based distances. The y-axis is different for each row:\non the first (top) row, the y-axis represents species functional distances in the multidimensional space. Thus, the closer species are to the 1:1 line, the better distances in the functional space fit trait-based ones.\non the second row, the y-axis shows the raw deviation of species distances in the functional space compared to trait-based distances. Thus, the raw deviation reflects the distance to the horizontal line.\non the third row (bottom), the y-axis shows the absolute or squared deviation of the (“scaled”) distance in the functional space. It is the deviation that is taken into account for computing the quality metric.\nCode\n\n\nmFD::quality.fspaces.plot(\n fspaces_quality = fspaces_quality_fruits,\n quality_metric = \"mad\",\n fspaces_plot = c(\"tree_average\", \"pcoa_2d\", \"pcoa_3d\",\n \"pcoa_4d\", \"pcoa_5d\", \"pcoa_6d\"),\n name_file = NULL,\n range_dist = NULL,\n range_dev = NULL,\n range_qdev = NULL,\n gradient_deviation = c(neg = \"darkblue\", nul = \"grey80\", pos = \"darkred\"),\n gradient_deviation_quality = c(low = \"yellow\", high = \"red\"),\n x_lab = \"Trait-based distance\")\n\n\n\n\n\nFor the 2D space, on the top row there are a lot of points below the 1:1 lines, meaning that distances are overestimated in this multidimensional space. Looking at panels, we can see that the 4D space is the one in which points are the closest to the 1:1 line on the top row,and the closest to the x-axis for the two bottom rows, which reflects a better quality compared to other functional spaces / dendrogram. For the dendrogram, we can see on the top row that species pairs arrange in horizontal lines, meaning that different trait-based distances have then the same cophenetic distance on the dendrogram.\n\n1.3.3. Testing the correlation between functional axes and traits\n\nmFD allows to test for correlations between traits and functional axes and then illustrate possible correlations (continuous traits = linear model is computed and r2 and associated p-value are returned; non-continuous traits = Kruskal-Wallis test is computed and eta2 statistic is returned). The function mFD::traits.faxes.cor() allows to test and plot correlation and needs the following arguments:\nsp_tr is the species x traits data.frame\nsp_faxes_coord is a matrix of species coordinates taken from the outputs of the mFD::quality.fspaces() function with columns representing axes on which functional space must be computed. For instance, in this tutorial, we will plot the functional space for 4 and 10 dimensions (cf. the two examples below). The whole sp_faxes_coord can be retrieved through the output of the mFD::quality.fspaces() function:\nCode\n\n\nsp_faxes_coord_fruits <- fspaces_quality_fruits$\"details_fspaces\"$\"sp_pc_coord\"\n\n\n\nplot is a logical value indicating whether correlations should be illustrated or not. If this option is set to TRUE, traits-axis relationships are plotted through scatterplot for continuous traits and boxplot for non-continuous traits.\nThe function mFD::traits.faxes.cor() works as follows:\n\nCode\n\n\nfruits_tr_faxes <- mFD::traits.faxes.cor(\n sp_tr = fruits_traits, \n sp_faxes_coord = sp_faxes_coord_fruits[ , c(\"PC1\", \"PC2\", \"PC3\", \"PC4\")], \n plot = TRUE)\n\n\n\nWe can print only traits with significant effect on position along one of the axis and look at the plots:\nCode\n\n\n## Print traits with significant effect ----\nfruits_tr_faxes$\"tr_faxes_stat\"[which(fruits_tr_faxes$\"tr_faxes_stat\"$\"p.value\" < 0.05), ]\n\n\n trait axis test stat value p.value\n1 Size PC1 Kruskal-Wallis eta2 0.308 0.0377\n3 Size PC3 Kruskal-Wallis eta2 0.326 0.0325\n5 Plant PC1 Kruskal-Wallis eta2 0.471 0.0049\n6 Plant PC2 Kruskal-Wallis eta2 0.382 0.0116\n8 Plant PC4 Kruskal-Wallis eta2 0.264 0.0360\n9 Climate PC1 Kruskal-Wallis eta2 0.731 0.0001\n13 Seed PC1 Kruskal-Wallis eta2 0.201 0.0402\n14 Seed PC2 Kruskal-Wallis eta2 0.593 0.0005\n20 Sugar PC4 Linear Model r2 0.682 0.0000\n\n## Plot ----\nfruits_tr_faxes$\"tr_faxes_plot\"\n\n\n\n\n\nWe can thus see that PC1 is mostly driven by Climate (temperate on the left and tropical on the right) and Plant Type (forb & shrub on the left vs tree & vine on the right) and Size (large fruits on the right) with weaker influence of Seed (eta2 < 0.25). Then, PC2 is mostly driven by Seed (no seed on the left and pit seed on the right) with weaker influence of Plant Type. PC3 is driven by only one trait, Size. And finally PC4 is mostly driven by Sugar (high sugar content on the right and low sugar content on the left) with a weaker influence of Plant Type.\n\n1.4. Plotting the selected functional space and position of species\n\nOnce the user has selected the dimensionality of the functional space, mFD allows you to plot the given multidimensional functional space and the position of species in all 2-dimensions spaces made by pairs of axes.\n\nThe mFD::funct.space.plot() function allows to illustrate the position of all species along pairs of space axes.\n\nThis function allows to plot with many possibilities to change colors/shapes of each plotted element. Here are listed the main arguments:\nsp_faxes_coord is a matrix of species coordinates taken from the outputs of the mFD::quality.fspaces() function with columns representing axes on which functional space must be computed. For instance, in this tutorial, we will plot the functional space for 4 and 10 dimensions (cf. the two examples below). The whole sp_faxes_coord can be retrieved through the output of the mFD::quality.fspaces() function:\n\nCode\n\n\nsp_faxes_coord_fruits <- fspaces_quality_fruits$\"details_fspaces\"$\"sp_pc_coord\"\n\n\n\n\nfaxes is a vector containing names of axes to plot. If set to NULL, the first four functional axes will be plotted.\nfaxes_nm is a vector containing labels of faxes (following faxes vector rank). If NULL, labels follow faxes vector names.\nrange_faxes is a vector to complete if the user wants to set specific limits for functional axes. If range_faxes = c(NA, NA), the range is computed according to the range of values among all axes.\nplot_ch is a logical value used to draw or not the 2D convex-hull filled by the global pool of species. Color, fill and opacity of the convex hull can be chosen through other inputs, please refer to the function’s help.\nplot_sp_nm is a vector containing species names to plot. If NULL, no species names plotted. Name size, color and font can be chosen through other inputs, please refer to the function’s help.\nplot_vertices is a logical value used to plot or not vertices with a different shape than other species. Be careful these representations are 2D representations, thus vertices of the convex-hull in the n-multidimensional space can be close to the center of the hull projected in 2D. Color, fill, shape and size of vertices can be chosen through other inputs, please refer to the function’s help.\ncheck_input is a recurrent argument in the mFD package. It defines whether inputs should be checked before computation or not. Possible error messages will thus be more understandable for the user than R error messages (Recommendation: set it as TRUE).\nother inputs are used to chose color, fill, size, and shape of species from the global pool, please refer to the function’s help.\n\nHere are the plots for the fruits & baskets dataset for the first four PCoA axis:\n\nCode\n\n\nbig_plot <- mFD::funct.space.plot(\n sp_faxes_coord = sp_faxes_coord_fruits[ , c(\"PC1\", \"PC2\", \"PC3\", \"PC4\")],\n faxes = c(\"PC1\", \"PC2\", \"PC3\", \"PC4\"),\n name_file = NULL,\n faxes_nm = NULL,\n range_faxes = c(NA, NA),\n plot_ch = TRUE,\n plot_vertices = TRUE,\n plot_sp_nm = NULL,\n check_input = TRUE)\n\nbig_plot$\"patchwork\"\n\n\n\n\n\nHere, the convex-hull of the species pool is plotted in white and axis have the same range to get rid of bias based on different axis scales. Species being vertices of the 4D convex hull are in purple.\n\nPart 2. Computing and plotting FD indices using the mFD package\n\nThe mFD::alpha.fd.multidim() function allows computing alpha and beta FD indices.\n\n2.1. Computing and plotting alpha FD indices\n\nUsing the alpha.fd.multidim() function, you can compute up to nine alpha FD indices:\nFDis Functional Dispersion: the biomass weighted deviation of species traits values from the center of the functional space filled by the assemblage i.e. the biomass-weighted mean distance to the biomass-weighted mean trait values of the assemblage.\nFRic Functional Richness: the proportion of functional space filled by species of the studied assemblage, i.e. the volume inside the convex-hull shaping species. To compute FRic the number of species must be at least higher than the number of functional axis + 1.\nFDiv Functional Divergence: the proportion of the biomass supported by the species with the most extreme functional traits i.e. the ones located close to the edge of the convex-hull filled by the assemblage.\nFEve Functional Evenness: the regularity of biomass distribution in the functional space using the Minimum Spanning Tree linking all species present in the assemblage.\nFSpe Functional Specialization: the biomass weighted mean distance to the mean position of species from the global pool (present in all assemblages).\nFMPD Functional Mean Pairwise Distance: the mean weighted distance between all species pairs.\nFNND Functional Mean Nearest Neighbour Distance: the weighted distance to the nearest neighbor within the assemblage.\nFIde Functional Identity: the mean traits values for the assemblage. FIde is always computed when FDis is computed.\nFOri Functional Originality: the weighted mean distance to the nearest species from the global species pool.\n\nA cheat sheet on alpha FD indices is available here\n\nIn this Practice we will only compute five of them. The function is used as follow:\nCode\n\n\nalpha_fd_indices_fruits <- mFD::alpha.fd.multidim(\n sp_faxes_coord = sp_faxes_coord_fruits[ , c(\"PC1\", \"PC2\", \"PC3\", \"PC4\")],\n asb_sp_w = baskets_fruits_weights,\n ind_vect = c(\"fdis\", \"fric\", \"fdiv\", \n \"fspe\", \"fide\"),\n scaling = TRUE,\n check_input = TRUE,\n details_returned = TRUE)\n\n\n\n\nThe arguments and their use are listed below:\nsp_faxes_coord is the species coordinates matrix. This dataframe gathers only axis of the functional space you have chosen based on step 4.\nasb_sp_w is the matrix linking species and assemblages they belong to (summarized in step 1).\nind_vect is a vector with names of diversity functional indices to compute.\nscaling is a logical value indicating whether indices should be scaled between 0 and 1. If scaling is to be done, this argument must be set to TRUE.\ncheck_input is a recurrent argument in the mFD package. It defines whether inputs should be checked before computation or not. Possible error messages will thus be more understandable for the user than R error messages (Recommendation: set it as TRUE).\ndetails_returned is used if the user wants to store information that are used in graphical functions. If the user wants to plot FD indices, then details_returned must be set to TRUE.\n\nN.B. Use lowercase letters to enter FD indices names\n\nThe function has two main outputs:\na data.frame gathering indices values in each assemblage (for FIde values, there are as many columns as there are axes to the studied functional space).\nCode\n\n\nfd_ind_values_fruits <- alpha_fd_indices_fruits$\"functional_diversity_indices\"\nfd_ind_values_fruits\n\n\n sp_richn fdis fric fdiv fspe\nbasket_1 8 0.4763773 0.162830681 0.5514453 0.4127138\nbasket_2 8 0.7207823 0.162830681 0.8064809 0.5781232\nbasket_3 8 0.7416008 0.162830681 0.8089535 0.5888104\nbasket_4 8 0.2958614 0.007880372 0.6080409 0.3106937\nbasket_5 8 0.3673992 0.007880372 0.7288912 0.3488358\nbasket_6 8 0.8001980 0.147936148 0.8937934 0.7930809\nbasket_7 8 0.8121314 0.147936148 0.8989094 0.7443406\nbasket_8 8 0.4678159 0.036480112 0.7113688 0.6363814\nbasket_9 8 0.5577452 0.036480112 0.7787237 0.6309078\nbasket_10 8 0.5505783 0.025774304 0.7741681 0.4587432\n fide_PC1 fide_PC2 fide_PC3 fide_PC4\nbasket_1 -0.01473662 -0.009461738 -0.05670043 -0.001823969\nbasket_2 0.01887361 -0.061601373 -0.04427402 0.021249327\nbasket_3 0.04724418 -0.056571400 -0.03631846 0.018045257\nbasket_4 0.03994897 0.052581211 -0.08413271 -0.001343112\nbasket_5 0.02349573 0.039069220 -0.08187248 -0.010262902\nbasket_6 0.24320913 -0.114434642 0.01394977 0.025500282\nbasket_7 0.13341179 -0.183609095 -0.01782549 0.021494300\nbasket_8 -0.24497368 0.036194656 0.04748935 -0.038827673\nbasket_9 -0.21021559 0.029339706 0.05516746 -0.041392184\nbasket_10 -0.05375867 -0.005743348 -0.05649324 0.041191011\n\n\na details list of data.frames and lists gathering information such as coordinates of centroids, distances and identity of the nearest neighbour, distances to the centroid, etc. The user does not have to directly use it but it will be useful if FD indices are then plotted. It can be retrieved through:\nCode\n\n\ndetails_list_fruits <- alpha_fd_indices_fruits$\"details\"\n\n\n\n\nThen, you can plot functional indices using the mFD::alpha.multidim.plot() for up to two assemblages:\n\nCode\n\n\nplots_alpha <- mFD::alpha.multidim.plot(\n output_alpha_fd_multidim = alpha_fd_indices_fruits,\n plot_asb_nm = c(\"basket_1\", \"basket_5\"),\n ind_nm = c(\"fdis\", \"fric\", \"fdiv\", \n \"fspe\", \"fide\"),\n faxes = NULL,\n faxes_nm = NULL,\n range_faxes = c(NA, NA),\n plot_sp_nm = NULL,\n save_file = FALSE,\n check_input = TRUE) \n\n\n\n\nThis function has a lot of arguments: most of them are graphical arguments allowing the user to chose colors, shapes, sizes, scales, etc. This tutorial only presents main arguments. To learn about the use of graphical arguments, check the function help file. The main arguments of this function are listed below:\noutput_alpha_fd_multidim is the output of the `mFD::alpha.fd.multidim() function.\nplot_asb_nm is a vector gathering name(s) of assemblage(s) to plot.\nind_vect is a vector gathering FD indices to plot. Plots are available for FDis, FIde, FEve, FRic, FDiv, FOri, FSpe, and FNND.\nfaxes is a vector containing names of axes to plot. You can only plot from two to four axes labels for graphical reasons.\nfaxes_nm is a vector with axes labels if the user ants different axes labels than faxes ones.\nrange_faxes is a vector with minimum and maximum values for axes. If range_faxes = c(NA, NA), the range is computed according to the range of values among all axes, all axes having thus the same range. To have a fair representation of species positions in all plots, all axes must have the same range.\nplot_sp_nm is a vector containing species names to plot. If NULL, then no name is plotted.\ncheck_input is a recurrent argument in mFD. It defines whether inputs should be checked before computation or not. Possible error messages will thus be more understandable for the user than R error messages (Recommendation: set it as TRUE.\nsize, color, fill, and shape arguments for each component of the graphs i.e. species of the global pool, species of the studied assemblage(s), vertices, centroids and segments. If you have to plot two assemblages, then inputs should be formatted as follow: c(pool = ..., asb1 = ..., asb2 = ...) for inputs used for global pool and studied assemblages and c(asb1 = ..., asb2 = ...) for inputs used for studied assemblages only.\n\nThen, using these arguments, here are the output plots for the fruits & baskets dataset:\n\nFRic representation: the colored shapes reflect the convex-hull of the studied assemblages and the white shape reflects the convex-hull of the global pool of species:\nCode\n\n\nplots_alpha$\"fric\"$\"patchwork\"\n\n\n\n\nFDiv representation: the gravity centers of vertices (i.e. species with the most extreme functional traits) of each assemblages are plotted as a square and a triangle. The two colored circles represent the mean distance of species to the gravity center for each assemblage. Species of each assemblage have different size given their relative weight into the assemblage.\nCode\n\n\nplots_alpha$\"fdiv\"$\"patchwork\"\n\n\n\n\nFSpe representation: colored traits represent distances of each species from a given assemblage to the center of gravity of the global pool (i.e center of the functional space). the center of gravity is plotted with a purple diamond. Species of each assemblage have different size given their relative weight into the assemblage.\nCode\n\n\nplots_alpha$\"fspe\"$\"patchwork\"\n\n\n\n\nFDis representation: colored traits represent distances of each species from a given assemblage to the center of gravity of species of the assemblage (defined by FIde values). The center of gravity of each assemblage is plotted using a square and a triangle. Species of each assemblage havedifferent size given their relative weight into the assemblage.\nCode\n\n\nplots_alpha$\"fdis\"$\"patchwork\"\n\n\n\n\nFIde representation:colored lines refer to the weighted average position of species of each assemblage along each axis. Species of each assemblage have different size given their relative weight into the assemblage.\nCode\n\n\nplots_alpha$\"fide\"$\"patchwork\"\n\n\n\n\nN.B. Using the mFD package, you can plot more than two assemblages but not with the alpha.multidim.plot() function. There are several specific functions for each step of the plot: build the background of the plot (background.plot()), plot the pool of species you are working on (pool.plot()), plot species from the studied assemblages (species.plot()) function and lastly plot the wanted metric using related function (fric.plot(), fdiv.plot(), fide.plot(),fdis.plot(), feve.plot(), fnnd.plot(), fori.plot(), fspe.plot()). Plots for different axes combination can be gathered into a single plot using the panels.to.patchwork() function.\n\n2.2. Computing and plotting beta FD indices\n\nN.B. Some Mac OS X 10.15 may encounter some issues with the beta_*() functions.\nmFD package allows you to compute beta diversity indices for each assemblage pairs following Villeger et al. 2013. For that we will use the mFD::beta.fd.multidim() function. This function can compute two families of functional beta diversity indices, either Jaccard or Sorensen.\nIn this example, we will use Jaccard index. For each assemblages pair, the dissimilarity index is decomposed into two additive components: turnover and nestedness-resultant.\nNB The turnover component is the highest if there is no shared traits combination between the two assemblages. The nestedness component is the highest if one assemblage hosts a small subset of the functional strategies present in the other.\nThe mFD::beta.fd.multidim() function has the main following arguments:\nCode\n\n\nbeta_fd_indices_fruits <- mFD::beta.fd.multidim(\n sp_faxes_coord = sp_faxes_coord_fruits[ , c(\"PC1\", \"PC2\", \"PC3\", \"PC4\")],\n asb_sp_occ = asb_sp_fruits_occ,\n check_input = TRUE,\n beta_family = c(\"Jaccard\"),\n details_returned = TRUE)\n\n\n\nsp_faxes_coord is the species coordinates matrix. This dataframe gathers only axis of the functional space you have chosen based on step 4.\nasb_sp_occ is the matrix of occurrence (coded as 0/1) of species assemblages (summarized in step 1).\ncheck_input is a recurrent argument in the mFD package. It defines whether inputs should be checked before computation or not. Possible error messages will thus be more understandable for the user than R error messages (Recommendation: set it as TRUE.\nbeta_family a character string for the type of beta-diversity index to compute, it can either be Jaccard or Sorensen.\ndetails_returned is a logical value indicating whether details of outputs must be stored. It should be stored if you plan to use the graphical function to illustrate beta diversity indices thereafter.\nThere are also other arguments for parallelisation options. Check the function help file for more explanation.\n\nThe function returns a list containing:\na dist object with beta indices values for each pair of assemblages:\nCode\n\n\nhead(beta_fd_indices_fruits$\"pairasb_fbd_indices\", 10)\n\n\n$jac_diss\n basket_1 basket_2 basket_3 basket_4\nbasket_2 3.920303e-15 \nbasket_3 3.920303e-15 3.920303e-15 \nbasket_4 9.654002e-01 9.654002e-01 9.654002e-01 \nbasket_5 9.654002e-01 9.654002e-01 9.654002e-01 0.000000e+00\nbasket_6 8.701848e-01 8.701848e-01 8.701848e-01 9.972695e-01\nbasket_7 8.701848e-01 8.701848e-01 8.701848e-01 9.972695e-01\nbasket_8 9.797030e-01 9.797030e-01 9.797030e-01 1.000000e+00\nbasket_9 9.797030e-01 9.797030e-01 9.797030e-01 1.000000e+00\nbasket_10 9.151338e-01 9.151338e-01 9.151338e-01 9.303584e-01\n basket_5 basket_6 basket_7 basket_8\nbasket_2 \nbasket_3 \nbasket_4 \nbasket_5 \nbasket_6 9.972695e-01 \nbasket_7 9.972695e-01 0.000000e+00 \nbasket_8 1.000000e+00 1.000000e+00 1.000000e+00 \nbasket_9 1.000000e+00 1.000000e+00 1.000000e+00 0.000000e+00\nbasket_10 9.303584e-01 9.983508e-01 9.983508e-01 9.702788e-01\n basket_9\nbasket_2 \nbasket_3 \nbasket_4 \nbasket_5 \nbasket_6 \nbasket_7 \nbasket_8 \nbasket_9 \nbasket_10 9.702788e-01\n\n$jac_turn\n basket_1 basket_2 basket_3 basket_4\nbasket_2 3.920303e-15 \nbasket_3 3.920303e-15 3.920303e-15 \nbasket_4 4.320333e-01 4.320333e-01 4.320333e-01 \nbasket_5 4.320333e-01 4.320333e-01 4.320333e-01 0.000000e+00\nbasket_6 8.627528e-01 8.627528e-01 8.627528e-01 9.723344e-01\nbasket_7 8.627528e-01 8.627528e-01 8.627528e-01 9.723344e-01\nbasket_8 9.425331e-01 9.425331e-01 9.425331e-01 1.000000e+00\nbasket_9 9.425331e-01 9.425331e-01 9.425331e-01 1.000000e+00\nbasket_10 5.990146e-01 5.990146e-01 5.990146e-01 8.385233e-01\n basket_5 basket_6 basket_7 basket_8\nbasket_2 \nbasket_3 \nbasket_4 \nbasket_5 \nbasket_6 9.723344e-01 \nbasket_7 9.723344e-01 0.000000e+00 \nbasket_8 1.000000e+00 1.000000e+00 1.000000e+00 \nbasket_9 1.000000e+00 1.000000e+00 1.000000e+00 0.000000e+00\nbasket_10 8.385233e-01 9.944208e-01 9.944208e-01 9.638833e-01\n basket_9\nbasket_2 \nbasket_3 \nbasket_4 \nbasket_5 \nbasket_6 \nbasket_7 \nbasket_8 \nbasket_9 \nbasket_10 9.638833e-01\n\n$jac_nest\n basket_1 basket_2 basket_3 basket_4 basket_5\nbasket_2 0.000000000 \nbasket_3 0.000000000 0.000000000 \nbasket_4 0.533366944 0.533366944 0.533366944 \nbasket_5 0.533366944 0.533366944 0.533366944 0.000000000 \nbasket_6 0.007431956 0.007431956 0.007431956 0.024935183 0.024935183\nbasket_7 0.007431956 0.007431956 0.007431956 0.024935183 0.024935183\nbasket_8 0.037169839 0.037169839 0.037169839 0.000000000 0.000000000\nbasket_9 0.037169839 0.037169839 0.037169839 0.000000000 0.000000000\nbasket_10 0.316119149 0.316119149 0.316119149 0.091835053 0.091835053\n basket_6 basket_7 basket_8 basket_9\nbasket_2 \nbasket_3 \nbasket_4 \nbasket_5 \nbasket_6 \nbasket_7 0.000000000 \nbasket_8 0.000000000 0.000000000 \nbasket_9 0.000000000 0.000000000 0.000000000 \nbasket_10 0.003930032 0.003930032 0.006395544 0.006395544\n\na list containing details such as inputs, vertices of the global pool and of each assemblage and FRic values for each assemblage\nCode\n\n\nbeta_fd_indices_fruits$\"details\"\n\n\n$inputs\n$inputs$sp_faxes_coord\n PC1 PC2 PC3 PC4\napple 0.0055715265 0.0350421604 -0.097471237 0.022402932\napricot 0.0051324906 0.1993950375 -0.095659935 0.041498534\nbanana 0.4180172546 -0.1414728845 0.008086992 0.006165812\ncurrant -0.3278449659 0.0536374098 0.049052945 -0.076408888\nblackberry -0.3034346496 0.0526909897 0.049135314 -0.142658171\nblueberry -0.2815708070 -0.0866665191 0.051316336 0.112502412\ncherry -0.0180809780 0.2978695529 -0.029313202 0.111166444\ngrape -0.2228504050 0.0885963887 0.225751135 0.190718259\ngrapefruit 0.1450603259 -0.0673074635 -0.119455606 -0.084037260\nkiwifruit -0.1550698937 -0.0814958746 0.005740138 0.086787104\nlemon 0.1067949113 0.0007714157 -0.088895714 -0.207026513\nlime 0.2079695595 0.0199956576 0.099157708 -0.266782185\nlitchi 0.2917434196 0.2537533311 0.202206065 0.041136776\nmango 0.4393412201 0.0559467870 -0.054626734 0.119804224\nmelon -0.1493941692 -0.2420723462 -0.151024241 0.070247222\norange 0.1236282949 -0.0086604744 -0.050235439 -0.046156784\npassion_fruit 0.1101264243 -0.1062790540 0.342728218 0.031929461\npeach 0.0351203321 0.1465415655 -0.199699124 0.049647666\npear -0.0005886084 0.0297927029 -0.105703762 0.010290065\npineapple 0.1991811945 -0.4756825960 0.075904777 0.042696533\nplum 0.0126064681 0.1989177835 -0.084010036 0.058965350\nraspberry -0.3070933066 0.0543878274 0.049178225 -0.156730076\nstrawberry -0.2917242495 -0.0898440618 0.025237344 -0.047647147\ntangerine 0.1039035285 0.0526165085 0.041894666 -0.048619225\nwater_melon -0.1465449176 -0.2404738440 -0.149294834 0.080107453\n\n$inputs$asb_sp_occ\n apple apricot banana currant blackberry blueberry cherry\nbasket_1 1 0 1 0 0 0 1\nbasket_2 1 0 1 0 0 0 1\nbasket_3 1 0 1 0 0 0 1\nbasket_4 1 0 0 0 0 0 0\nbasket_5 1 0 0 0 0 0 0\nbasket_6 1 0 1 0 0 0 0\nbasket_7 1 0 1 0 0 0 0\nbasket_8 0 0 0 1 1 1 1\nbasket_9 0 0 0 1 1 1 1\nbasket_10 1 1 0 0 0 0 0\n grape grapefruit kiwifruit lemon lime litchi mango melon\nbasket_1 0 0 0 1 0 0 0 1\nbasket_2 0 0 0 1 0 0 0 1\nbasket_3 0 0 0 1 0 0 0 1\nbasket_4 0 0 1 1 0 0 0 0\nbasket_5 0 0 1 1 0 0 0 0\nbasket_6 0 0 0 0 1 1 1 0\nbasket_7 0 0 0 0 1 1 1 0\nbasket_8 1 0 0 1 0 0 0 0\nbasket_9 1 0 0 1 0 0 0 0\nbasket_10 1 1 0 0 0 0 0 1\n orange passion_fruit peach pear pineapple plum raspberry\nbasket_1 0 1 0 1 0 0 0\nbasket_2 0 1 0 1 0 0 0\nbasket_3 0 1 0 1 0 0 0\nbasket_4 1 0 1 1 0 1 0\nbasket_5 1 0 1 1 0 1 0\nbasket_6 1 0 0 0 1 0 0\nbasket_7 1 0 0 0 1 0 0\nbasket_8 0 0 0 0 0 0 1\nbasket_9 0 0 0 0 0 0 1\nbasket_10 0 0 0 1 0 1 0\n strawberry tangerine water_melon\nbasket_1 1 0 0\nbasket_2 1 0 0\nbasket_3 1 0 0\nbasket_4 0 1 0\nbasket_5 0 1 0\nbasket_6 0 0 1\nbasket_7 0 0 1\nbasket_8 1 0 0\nbasket_9 1 0 0\nbasket_10 1 0 0\n\n\n$pool_vertices\n [1] \"grape\" \"lemon\" \"water_melon\" \"banana\" \n [5] \"raspberry\" \"cherry\" \"blueberry\" \"grapefruit\" \n [9] \"melon\" \"strawberry\" \"peach\" \"apricot\" \n[13] \"passion_fruit\" \"litchi\" \"lime\" \"pineapple\" \n[17] \"mango\" \"currant\" \n\n$asb_FRic\n basket_1 basket_2 basket_3 basket_4 basket_5 \n0.162830681 0.162830681 0.162830681 0.007880372 0.007880372 \n basket_6 basket_7 basket_8 basket_9 basket_10 \n0.147936148 0.147936148 0.036480112 0.036480112 0.025774304 \n\n$asb_vertices\n$asb_vertices$basket_1\n[1] \"lemon\" \"melon\" \"pear\" \"apple\" \n[5] \"passion_fruit\" \"cherry\" \"strawberry\" \"banana\" \n\n$asb_vertices$basket_2\n[1] \"lemon\" \"melon\" \"pear\" \"apple\" \n[5] \"passion_fruit\" \"cherry\" \"strawberry\" \"banana\" \n\n$asb_vertices$basket_3\n[1] \"lemon\" \"melon\" \"pear\" \"apple\" \n[5] \"passion_fruit\" \"cherry\" \"strawberry\" \"banana\" \n\n$asb_vertices$basket_4\n[1] \"peach\" \"lemon\" \"tangerine\" \"pear\" \"plum\" \n[6] \"orange\" \"kiwifruit\"\n\n$asb_vertices$basket_5\n[1] \"peach\" \"lemon\" \"tangerine\" \"pear\" \"plum\" \n[6] \"orange\" \"kiwifruit\"\n\n$asb_vertices$basket_6\n[1] \"litchi\" \"lime\" \"apple\" \"banana\" \n[5] \"orange\" \"pineapple\" \"mango\" \"water_melon\"\n\n$asb_vertices$basket_7\n[1] \"litchi\" \"lime\" \"apple\" \"banana\" \n[5] \"orange\" \"pineapple\" \"mango\" \"water_melon\"\n\n$asb_vertices$basket_8\n[1] \"strawberry\" \"blueberry\" \"raspberry\" \"cherry\" \"grape\" \n[6] \"lemon\" \"currant\" \n\n$asb_vertices$basket_9\n[1] \"strawberry\" \"blueberry\" \"raspberry\" \"cherry\" \"grape\" \n[6] \"lemon\" \"currant\" \n\n$asb_vertices$basket_10\n[1] \"grape\" \"melon\" \"plum\" \"apricot\" \"grapefruit\"\n[6] \"strawberry\"\n\na vector containing the FRic value for each assemblage retrieved through the details_beta list:\nCode\n\n\nbeta_fd_indices_fruits$\"details\"$\"asb_FRic\"\n\n\n basket_1 basket_2 basket_3 basket_4 basket_5 \n0.162830681 0.162830681 0.162830681 0.007880372 0.007880372 \n basket_6 basket_7 basket_8 basket_9 basket_10 \n0.147936148 0.147936148 0.036480112 0.036480112 0.025774304 \n\n\na list of vectors containing names of species being vertices of the convex hull for each assemblage retrieved through the details_beta list:\n\n\nbeta_fd_indices_fruits$\"details\"$\"asb_vertices\"\n\n\n$basket_1\n[1] \"lemon\" \"melon\" \"pear\" \"apple\" \n[5] \"passion_fruit\" \"cherry\" \"strawberry\" \"banana\" \n\n$basket_2\n[1] \"lemon\" \"melon\" \"pear\" \"apple\" \n[5] \"passion_fruit\" \"cherry\" \"strawberry\" \"banana\" \n\n$basket_3\n[1] \"lemon\" \"melon\" \"pear\" \"apple\" \n[5] \"passion_fruit\" \"cherry\" \"strawberry\" \"banana\" \n\n$basket_4\n[1] \"peach\" \"lemon\" \"tangerine\" \"pear\" \"plum\" \n[6] \"orange\" \"kiwifruit\"\n\n$basket_5\n[1] \"peach\" \"lemon\" \"tangerine\" \"pear\" \"plum\" \n[6] \"orange\" \"kiwifruit\"\n\n$basket_6\n[1] \"litchi\" \"lime\" \"apple\" \"banana\" \n[5] \"orange\" \"pineapple\" \"mango\" \"water_melon\"\n\n$basket_7\n[1] \"litchi\" \"lime\" \"apple\" \"banana\" \n[5] \"orange\" \"pineapple\" \"mango\" \"water_melon\"\n\n$basket_8\n[1] \"strawberry\" \"blueberry\" \"raspberry\" \"cherry\" \"grape\" \n[6] \"lemon\" \"currant\" \n\n$basket_9\n[1] \"strawberry\" \"blueberry\" \"raspberry\" \"cherry\" \"grape\" \n[6] \"lemon\" \"currant\" \n\n$basket_10\n[1] \"grape\" \"melon\" \"plum\" \"apricot\" \"grapefruit\"\n[6] \"strawberry\"\n\nThen, the package allows the user to illustrate functional beta-diversity indices for a pair of assemblages in a multidimensional space using the mFD::beta.multidim.plot() function. The output of this function is a figure showing the overlap between convex hulls shaping each of the two species assemblages.\nThe plotting function has a large number of arguments, allowing the user to chose graphical options. Only main arguments are listed below:\nCode\n\n\nbeta_plot_fruits <- mFD::beta.multidim.plot(\n output_beta_fd_multidim = beta_fd_indices_fruits,\n plot_asb_nm = c(\"basket_1\", \"basket_4\"),\n beta_family = c(\"Jaccard\"),\n plot_sp_nm = c(\"apple\", \"lemon\", \"pear\"),\n faxes = paste0(\"PC\", 1:4),\n name_file = NULL,\n faxes_nm = NULL,\n range_faxes = c(NA, NA),\n check_input = TRUE)\n\n\n\noutput_beta_fd_multidim is the output of the mFD::beta.fd.multidim() function retrieved before as beta_fd_indices.\nplot_asb_nm is a vector containing the name of the two assemblages to plot. Here plots of indices will be shown for basket_1 and basket_4.\nbeta_family refers to the family of the plotted index. It must be the same as the family chosen to compute beta functional indices values with the mFD::beta.fd.multidim() function.\nplot_sp_nm is a vector containing the names of species the user want to plot, if any. If no the user does not want to plot any species name, then this argument must be set up to NULL. Here, apple, cherry and lemon will be plotted on the graph.\nfaxes is a vector containing the names of the functional axes of the plotted functional space. Here, the figure will be plotted for PC1, PC2 and PC3. This function allows you to plot between two and four axes for graphical reasons.\nname_file is a character string with the name of the file to save the figure (without extension). If the user does not want to save the file and only display it, this argument must be set up to NULL.\nfaxes_nm is a vector containing the axes labels for the figure if the user wants to set up different labels than those contained in faxes.\nrange_faxes is a vector with minimum and maximum values of functional axes. To have a fair representation of the position of species in all plots, axes should have the same range. If the user wants the range to be computed according to the range of values among all axes, this argument must be set up to c(NA, NA).\ncheck_input is a recurrent argument in the mFD package. It defines whether inputs should be checked before computation or not. Possible error messages will thus be more understandable for the user than R error messages (Recommendation: set it as TRUE)\nOthers arguments to set up colors, shapes, sizes and, text fonts are also available. For more information about them, read the function help file.\nThen, the function returns each graph for each functional axes combination and also a multipanel plot with all combinations of axes and the graph caption. Here is the multipanel for the fruits exaample:\n\n\nbeta_plot_fruits$\"patchwork\"\n\n\n\n\nFor each assemblage, the associated convex hull is plotted in a different colour and indices values are printed on the right corner of the plot. Vertices of the convex hull of a given assemblage can be plotted with a different symbol such as in this example. Species of all assemblages are plotted with gray cross and the associated convex hull is plotted in white.\n\nPart 3. Functional rarity\nIn this part we’ll be using our built functional space to compute functional originality indices. The questions we’ll answer are:\nWhat are functionally distinct fruits compared to all fruits together?\nAre some of these fruits distinct at regional scale but not when looking at specific baskets?\n3.1 Components of functional rarity: trait originality and rarity\nFunctional originality indices (also named functional rarity indices) measures how different are the trait of a target species compared to other ones among a set. Their idea is analogous to the rarity concept in terms of abundance: some species are rare because they show low abundance, some are common because of their high abundance. Well, functionally original species are original because they display trait values distant from most other species.\nThe indices were initially proposed as complimentary facets: one for “classical” rarity and one for trait “rarity” (= originality) Violle et al. 2017. With this framework, a species could be either rare or common, with either original or common traits. All combinations are possible. For example a species can be rare in abundance but have common traits. A species could also be common in abundance but original in terms of traits.\nViolle et al. (2014) further declined the framework along two spatial scales, local and regional. The local scale is scale of the site or the assemblage, where species interact directly. The regional scale is the species pools scale, containing all species occurring in a given set of assemblages.\nThis initial framework thus contained 16 different possibilities between the different kinds of rarity (trait or abundance) and the spatial scales.\nMore recent studies tend to focus only on the trait originality axis and that’s the one we’ll be studying here.\n3.2 Different indices of functional originality\nOne specificity of functional originality indices is that we compute them on a species basis and not per sites. This means that for each species we will get one value.\nThe two proposed indices of functional originality are functional distinctiveness (Di) and functional uniqueness (Ui). They were initially envisioned at different spatial scales, with functional distinctiveness computed at local scale (and considering abundance) while functional uniqueness was to be computed at regional scales (without considering abundances).\n Scheme showing how Distinctiveness (Di) and Uniqueness (Ui) are computedFunctional distinctiveness is the mean of dissimilarity of the focal species to all the other species of the set of interest. It can be abundance-weighted if needed.\nFunctional uniqueness is the smallest dissimilarity that exists between the focal species and the all other species in the set. It does not consider the abundance of any species.\n3.3 Computing functional originality\nTo compute functional originality indices we will two object: a functional dissimilarity matrix and a site-species matrix. We will be reusing the ones we defined in part 1 for that.\nBecause the funrar package follows strictly the framework defined by Violle et al. (2017), we have to consider the spatial scale at which we compute distinctiveness and uniqueness.\n3.3.1 At regional scale\nAt regional scale, we can compute distinctiveness using the distinctiveness_global() function. The first argument should be a functional dissimilarity matrix and the second argument gives the name of the output column.\n\n\nlibrary(\"funrar\")\n\nsp_di <- distinctiveness_global(sp_dist_fruits, di_name = \"distinctiveness\")\n\nhead(sp_di)\n\n\n species distinctiveness\n1 apple 0.2930460\n2 apricot 0.3421360\n3 banana 0.4972814\n4 currant 0.4496738\n5 blackberry 0.4272436\n6 blueberry 0.4264538\n\ndim(sp_di)\n\n\n[1] 25 2\n\nWe get one value of distinctiveness per species. It only considers the functional dissimilarity of all species in the dissimilarity matrix without considering their spatial distributions. We get one value of distinctiveness per species.\n\n\nsummary(sp_di)\n\nquantile(sp_di$distinctiveness, probs = seq(0, 1, by = 0.1))\n\nsubset(sp_di, distinctiveness >= 0.48)\n\n\n\nWhen looking at the most distinct fruits we see that banana, litchi, and pineapple, are the most distinct from their characteristics.\nFor the choice or dissimilarity matrix we can use the raw dissimilarity matrix computed directly on raw traits values among species, as we did here. Another option would be to compute a new functional dissimilarity matrix based on the selected functional axes. One advantage of the latter is that it already takes into account the correlation between traits.\nLet’s recompute regional functional distinctiveness based on the four selected functional axes. Because the space comes from a PCA, we can directly use euclidean distance.\n\n\nnew_dissim <- dist(sp_faxes_coord_fruits[, c(\"PC1\", \"PC2\", \"PC3\", \"PC4\")])\n\nsp_di_alt <- distinctiveness_global(new_dissim, di_name = \"alt_di\")\n\n\n\nWe can now compare both distinctiveness values.\n\n\nsp_all_di <- merge(sp_di, sp_di_alt, by = \"species\")\n\nplot(sp_all_di$distinctiveness, sp_all_di$alt_di)\n\n\n\ncor.test(sp_all_di$distinctiveness, sp_all_di$alt_di)\n\n\n\n Pearson's product-moment correlation\n\ndata: sp_all_di$distinctiveness and sp_all_di$alt_di\nt = 17.91, df = 23, p-value = 5.281e-15\nalternative hypothesis: true correlation is not equal to 0\n95 percent confidence interval:\n 0.9232161 0.9851024\nsample estimates:\n cor \n0.9659697 \n\nBoth seems very correlated, so in our case using either one should be fine. However, it can be better to use dissimilarity based on a reduced number of well-defined axes because: (1) there are more interpretable thanks to the multivariate analysis, (2) the first one contain de most information, (3) they explicitly take into account potentially strong correlations between provided traits. We’ll stick here with raw dissimilarity for the sake of simplicity.\nTo compute uniqueness at regional scale we also need the regional level functional dissimilarity matrix with the uniqueness() function, and the site-species matrix:\n\n\nsp_ui <- uniqueness(\n pres_matrix = baskets_fruits_weights,\n as.matrix(sp_dist_fruits)\n)\n\nhead(sp_ui)\nquantile(sp_ui$Ui, probs = seq(0, 1, by = 0.1))\n\nsubset(sp_ui, Ui >= 0.21)\n\n\n\nNote that we have to transform the dissimilarity object sp_dist_fruits into a matrix explicitly so that the function uniqueness() works.\nBased on these results we see that banana, passion fruit, and pineapple are the most isolated fruits in the functional space. Meaning that they have the most distant nearest neighbors.\nSo we see that some species can be regionally distinct and regionally unique (banana and pineapple), while some can be not so regionally distinct but regionally unique (passion fruit).\n3.3.2 At local scale\nAt local scale we can use similar logic but we will obtain one value per species per site.\nFor distinctiveness we can use the distinctiveness() function:\n\n\nsp_local_di <- distinctiveness(\n baskets_fruits_weights, as.matrix(sp_dist_fruits)\n)\n\nsp_local_di[1:6, 1:6]\n\n\n apple apricot banana currant blackberry blueberry\nbasket_1 0.1977721 NA 0.4642749 NA NA NA\nbasket_2 0.2852373 NA 0.5243089 NA NA NA\nbasket_3 0.2902663 NA 0.5219277 NA NA NA\nbasket_4 0.1136474 NA NA NA NA NA\nbasket_5 0.1393697 NA NA NA NA NA\nbasket_6 0.4138809 NA 0.3063492 NA NA NA\n\nidentical(dim(sp_local_di), dim(baskets_fruits_weights))\n\n\n[1] TRUE\n\nNote: because we provided a site-species matrix that contained “abundance” values (here the weights of the fruits in our baskets), the distinctiveness() is going to use them in its computation. If we want it not to consider abundances we need to convert the site-species matrix into a presence-absence matrix.\nWe get exactly the same number of sites and species as provided in the lists of baskets. Looking at the first column we see that the distinctiveness of apple varies a lot. Let’s see if can see how much it varies and why.\n\n\nsp_local_di[, 1]\n\n\n basket_1 basket_2 basket_3 basket_4 basket_5 basket_6 basket_7 \n0.1977721 0.2852373 0.2902663 0.1136474 0.1393697 0.4138809 0.3861698 \n basket_8 basket_9 basket_10 \n NA NA 0.2313228 \n\nIt varies from around 0.11 in basket 4 to up to 0.41 in basket 6. We can lookup the composition of these baskets to understand why:\n\n\nbaskets_fruits_weights[c(4, 6),]\n\n\n apple apricot banana currant blackberry blueberry cherry\nbasket_4 300 0 0 0 0 0 0\nbasket_6 100 0 200 0 0 0 0\n grape grapefruit kiwifruit lemon lime litchi mango melon\nbasket_4 0 0 100 100 0 0 0 0\nbasket_6 0 0 0 0 200 200 500 0\n orange passion_fruit peach pear pineapple plum raspberry\nbasket_4 400 0 300 400 0 200 0\nbasket_6 100 0 0 0 500 0 0\n strawberry tangerine water_melon\nbasket_4 0 200 0\nbasket_6 0 0 200\n\nWe can see that basket 4 contains fruits of similar size, origin and sweetness of apples: peach, pear, plums. This decreases the local distinctiveness of apples. While basket 6 contains more tropical fruits that are quite different in terms of size and sugar from apples.\nTo compute uniqueness at the site scale, we must use a more complex expression as it was not envisioned for local computation:\n\n\nbasket_ui <- apply(\n baskets_fruits_weights, 1,\n function(single_site, dist_m) {\n single_site = single_site[single_site > 0 & !is.na(single_site)]\n uniqueness(t(as.matrix(single_site)), dist_m)\n }, dist_m = as.matrix(sp_dist_fruits)\n)\n\nhead(basket_ui[1])\n\n\n$basket_1\n species Ui\n1 apple 0.008791209\n2 banana 0.375274725\n3 cherry 0.233379121\n4 lemon 0.199587912\n5 melon 0.190796703\n6 passion_fruit 0.414148352\n7 pear 0.008791209\n8 strawberry 0.190796703\n\nAs we had to manually build the function to compute the local uniqueness the results are strangely formatted.\nWe provide here a function that can help them to be more easily read:\n\n\nbasket_ui <- lapply(names(basket_ui), function(x) {\n single_basket = basket_ui[[x]]\n single_basket$site = x\n \n return(single_basket)\n})\n\nbasket_ui <- do.call(rbind, basket_ui)[, c(3, 1, 2)]\n\n\n\nThen we can again look at the apple to see how its uniqueness varies across baskets.\n\n\nsubset(basket_ui, species == \"apple\")\n\n\n site species Ui\n1 basket_1 apple 0.008791209\n9 basket_2 apple 0.008791209\n17 basket_3 apple 0.008791209\n25 basket_4 apple 0.008791209\n33 basket_5 apple 0.008791209\n41 basket_6 apple 0.117170330\n49 basket_7 apple 0.117170330\n73 basket_10 apple 0.008791209\n\nWe see that apple have the same uniqueness everywhere but in baskets 6 and 7. This means that it has the same nearest neighbor (in functional space) across all of these baskets. But that its closest neighbor is further away in baskets 6 and 7.\n3.4 Plotting functional originality\nfunrar does not come with visualization functions so that you can use whatever tool you prefer to plot the metrics. Here we are going to use ggplot2 visualize the results. However, feel free to use anything plotting packages you would like. If you’re not fluent in ggplot2 don’t worry this section will mostly be about interpreting the figures rather than commenting on code.\nWe already saw in part 1 how to visualize the functional space using the pre-made functions of mFD. Here we will use our own functions to be able to color species in function of their functional originality.\n\n\n# Make a summary data.frame\nsp_coord_di_ui <- as.data.frame(sp_faxes_coord_fruits[, 1:2])\nsp_coord_di_ui$species <- rownames(sp_coord_di_ui)\nrownames(sp_coord_di_ui) <- NULL\nsp_coord_di_ui <- sp_coord_di_ui[, c(3, 1, 2)]\nsp_coord_di_ui <- merge(sp_coord_di_ui, sp_di, by = \"species\")\nsp_coord_di_ui <- merge(sp_coord_di_ui, sp_ui, by = \"species\")\n\n\n\n\n\nlibrary(\"ggplot2\")\n\nplot_reg_distinctiveness <- ggplot(sp_coord_di_ui, aes(PC1, PC2)) +\n geom_hline(yintercept = 0, linetype = 2) +\n geom_vline(xintercept = 0, linetype = 2) +\n geom_point(aes(color = distinctiveness)) +\n ggrepel::geom_text_repel(aes(label = species)) +\n scale_color_viridis_c(\"Functional\\nDistinctiveness\") +\n theme_bw() +\n theme(aspect.ratio = 1)\n\nplot_reg_uniqueness <- ggplot(sp_coord_di_ui, aes(PC1, PC2)) +\n geom_hline(yintercept = 0, linetype = 2) +\n geom_vline(xintercept = 0, linetype = 2) +\n geom_point(aes(color = Ui)) +\n ggrepel::geom_text_repel(aes(label = species)) +\n scale_color_viridis_c(\"Functional\\nUniqueness\") +\n theme_bw() +\n theme(aspect.ratio = 1)\n\npatchwork::wrap_plots(plot_reg_distinctiveness, plot_reg_uniqueness)\n\n\n\n\nWe can clearly see that, by definition, most functionally distinct species are on the edges of the functional space (pineapple, litchi, mango). If we compare both plots, we realize that functional distinctiveness doesn’t always come with functional uniqueness. One strange observation is that passion-fruit has a very functional uniqueness even though it seems quite in the middle of the points. This is a consequence of using the raw trait dissimilarity matrix instead of the projected axes. We’re are here visualizing the position of passion fruit in a 2D space while it should be considered in a 5D space, so it may seem close to other points in 2D while it is further away in reality.\nAs was done with mFD to correlate the functional axes with species’ traits we can correlate functional distinctiveness to specific traits in order to see which traits are mainly driving distinctiveness.\nXXX\nRegarding local level functional originality indices, the visualization can be more difficult to grasp and depends highly on the question. Would you rather focus on visualizing the functional distinctiveness of one species across communities? Compare the distribution of functional distinctiveness values across communities?\nOne idea to keep in mind is that averaging functional distinctiveness per community is exactly equal to computing functional dispersion. Functional originality is computed on a species basis, so we should be aware that if we are rather interested by community properties than we can compute functional diversity metrics which are much more appropriate.\nIf we take again our example of the apple we can see to what extent its functional distinctiveness varies across baskets compared to lemon.\n\n\nlocal_di_ap <- as.data.frame(sp_local_di[, c(1, 11)])\nlocal_di_ap$basket <- rownames(local_di_ap)\n\n\n\nYou can of course then compute relationship between environmental covariates and functional originality values. Because we don’t have any covariable in our fruit baskets we will stop the plotting session here.\n\n\n\n",
"last_modified": "2022-06-15T10:14:21+00:00"
},
{
"path": "resources.html",
"title": "Resources",
"author": [],
"contents": "\n\nRecommended papers\nGrenié M, Denelle P, Tucker CM, Munoz F & Violle C (2017) funrar: An R package to characterize functional rarity. Diversity and Distributions, 23, 1365-1371. DOI: 10.1111/ddi.12629 \nMagneville C, Loiseau N, Albouy C, Casajus N, Claverie T, Escalas A, Leprieur F, Maire E, Mouillot D & Villéger S (2022) mFD: an R package to compute and illustrate the multiple facets of functional diversity. Ecography. DOI: 10.1111/ecog.05904 \nMaire E, Grenouillet G, Brosse S & Villéger S (2015) Assessing functional space quality. Global Ecology and Biogeography, 24, 728-740. DOI: 10.1111/geb.12299 \nMouillot D, Graham NAJ, Villéger S, Mason NWH & Bellwood DR (2013) A functional approach reveals community responses to disturbances. Trends in Ecology & Evolution, 28, 167-177. DOI: 10.1016/j.tree.2012.10.004 \nVilléger S, Mason NWH & Mouillot D (2008) New multidimensional functional diversity indices for a multifaceted framework in functional ecology. Ecology, 89, 2290-2301. DOI: 10.1890/07-1206.1 \nCorrections\nIf you see mistakes or want to suggest changes, please Create an issue on the source repository.\nReuse\nThe material of this website is licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/frbcesab/workshop-free/.\nCitation\nCasajus N, Grénié M, Magneville C & Villéger S (2022) Workshop FRB-CESAB & FREE Working Group: Functional Rarity and Diversity in Ecology.\n\n\n\n",
"last_modified": "2022-06-15T10:14:22+00:00"
}
],
"collections": []
}