CmlMagneville / mFD

:package: A Computation of Functional Spaces and Functional Diversity Indices

Home Page:https://cmlmagneville.github.io/mFD/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not an issue: Using Fuzzy traits for computing Alpha Diversity Indices

poudro1 opened this issue · comments

Hello,

I Have been using the mFD package for my dataset that includes 2 fuzzy traits and 2 non-fuzzy traits. I noticed that in the workflows that are provided for learning to work with the package, fuzzy traits are only used when calculating diversity indices based on Hill Numbers or Beta Diversity. I was wondering if this is because the authors ommited fuzzy traits from the alpha diversity tutorial to keep it simple or if you don't advise using fuzzy-traits for calculating alpha diversity indices.

This is not an "issue" but I didn't find another channel to communicate this question, clarification would be appreciated.

Kind Regards!

Hi,
We omitted fuzzy traits in the general workflow showing how to compute alpha and beta indices in a multidimensional space to keep the example simple. But it's also possible to follow this workflow with fuzzy traits 😉

Hi,

It's a warning message from the gawdis() function of the gawdis package. I think the warning is made based on a check for each trait modality, but you can check the code here: https://rdrr.io/cran/gawdis/src/R/gawdis.R#google_vignette (last lines for the warning message). For more information you can read the gawdis package description and the paper from De Bello (https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.13537).
In the mFD package, we chose not to include this corrected-weight approach but if you want to use it, you can use the gawdis::gawdis() function instead of mFD::funct.dist() and use its outputs in other mFD functions.

Note: For more questions about the package or challenges you encounter while using for your analyses, don't hesitate to contact me by email 😊 - Issues are made for code bugs and fix 🐛 (I'll try to do new page on the mFD website to compile the FAQs soon)
Camille

Hi,

Thank you for your feedback! We wrote in the funct.dist() help that traits names should be written as in the species*traits data frame but to be more explicit we have just added a check as it can lead to mistakes when using traits weights (as you said). It's now checked on the development version and a new version of the mFD package will be soon avalaible on CRAN.

However, it should not currently be possible to define weights for fuzzy traits with the mFD package, as written in the help of the funct_dist() function and in the general workflow tutorial. In fact, there is a step checking if you have fuzzy traits and weights, and if so, the function should stop (cf l.155-158 of the funct.dist() function here: https://github.com/CmlMagneville/mFD/blob/main/R/funct_dist_computation.R). So I don't understand why your code goes on, are you sure that your inputs have the right format?

Hey,

I did some testing, turns out that the funct.dist() function in mFD actually computes weights with fuzzy traits but only if you are setting the argument "w.type= value", using a user column in the form of a trait_weight column in the trait category data frame however, stops you from going any further with fuzzy traits:

My traits are basically 2 continous and 2 fuzzy traits, so for testing purposes I used the "sugar" and "use" traits from the fruit_traits dataset that comes with the package

library(mFD)
library(gawdis)
# selecting the traits
fruit_traits<-fruit_traits[,5:8]
fruit_traits_cat<-fruit_traits_cat[5:8,]

# using the funct.dist with the argument weight_type="equal" and metric ="gower"
dist_mFD<-mFD::funct.dist(
     sp_tr  = fruits_traits,
     tr_cat = fruits_traits_cat,
     metric = "gower",
     scale_euclid  = "scale_center",
     ordinal_var = "classic",
     weight_type = "equal",
     stop_if_NA  = TRUE)

# manually building the same distance matrix but with the gawdis function
dist_gaw<-gawdis(x = fruits_traits,w.type = "equal",groups = c(1,2,2,2),fuzzy = c(2))

Now if I use the attr() function to call the weights for both objects we can see they are identical:
image
image

Plotting both of them also shows they are identical:
image

However, trying to do the same thing with the funct.dist() function but with a trait_weight column stops the function from going further:

trait_weight<-c(0.5,0.16,0.16,0.16)
fruit_traits_cat<-cbind(fruits_traits_cat,trait_weight)
dist_mFD<-mFD::funct.dist(
     sp_tr  = fruits_traits,
     tr_cat = fruits_traits_cat,
     metric = "gower",
     scale_euclid  = "scale_center",
     ordinal_var = "classic",
     weight_type = "user",
     stop_if_NA  = TRUE)

Yields this result
image

Just to reitirate on my first point, that mismatching the order between trait and trait category data frames messes up the functional space

fruits_traits_inv<-fruits_traits[,c(4,3,2,1)]
dist_mFD_inv <- mFD::funct.dist(
  sp_tr  = fruits_traits_inv,
  tr_cat = fruits_traits_cat,
  metric = "gower",
  scale_euclid  = "scale_center",
  ordinal_var = "classic",
  weight_type = "equal",
  stop_if_NA  = TRUE)
attr(dist_mFD_inv,"weights")
attr(dist_mFD,"weights")

image
And if we plot them, they are very different
image

Hi,
It's normal that your first test gives the same results as you're not adding weight to each trait (you set weight_type = equal for the funct.dist() funtion and w.type = equal for the gawdis function). When I said "should not currently be possible to define weights for fuzzy traits with the mFD package" I was talking about giving different weights to the different traits.
For traits order, it has been corrected this morning (so ok in the development version of the package) and the version of the mFD package on the CRAN will be udated in a few hours (cf Issue #38).
If you have any other question, we can continue by email, as Github Issues are made for code bugs and fix 🐛
Camille