Closed poudro1 closed 8 months ago
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 😉
Thanks for the response!
On another note, I noticed that when computing the distance matrix a warning pops up, something like "consider ommiting (column that is part of a fuzzy trait) from the analysis because of uneven distribution"
I understand that having traits with uneven distributions could lead to altered results, but the traits in question are usually a proportional value from 0 to 1 that summed with other columns for the same fuzzy trait add up to 1. I was wondering if it is actually safe to ignore this warning for fuzzy traits.
My guess is that whatever is behind the warning thinks that each column is a trait, despiste taking into account that they are actually the same fuzzy-trait and correctly calculating distances between species
A quarta, 21/02/2024, 16:17, Camille Magneville @.***> escreveu:
Hi, We omitted fuzzy traits in the general workflow showing how to compute alpha and beta indices indices in a multidimensional space to keep the example simple. But it's also possible to follow this workflow with fuzzy traits 😉
— Reply to this email directly, view it on GitHub https://github.com/CmlMagneville/mFD/issues/37#issuecomment-1957163029, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3IZ6ARRUBRHR53TYL6CCJTYUYM2HAVCNFSM6AAAAABDTKQ7DOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJXGE3DGMBSHE . You are receiving this because you authored the thread.Message ID: @.***>
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
Thank you I think this is exactly what I needed, i checked the weights that I had and it turned out that some fuzzy categories were having a very disproportional weight in the final distance matrix, switched to the gawdis() function and now it seems to produce better results when calculating alpha diversity indices.
In the process I think I actually ran into a bug. It seems that the order of the traits in the trait data-frame has to be the exact same order as the trait category data-frame, otherwise weights are attributed in the order that appears in the trait category data-frame and can therefore be different from the intended one. In my case, it was switching the weight of a fuzzy category (should be 0.05) with a quantitive trait (should be 0.25). I simply switched my data-frames so they both match. Don't know whether this is actually a bug or a feature.
Thank you very much for your insightfull response.
On Fri, 23 Feb 2024 at 10:59, Camille Magneville @.***> wrote:
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
— Reply to this email directly, view it on GitHub https://github.com/CmlMagneville/mFD/issues/37#issuecomment-1961121327, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3IZ6ATGL42CCSC4V7PZ5N3YVBY7ZAVCNFSM6AAAAABDTKQ7DOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRRGEZDCMZSG4 . You are receiving this because you authored the thread.Message ID: @.***>
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:
Plotting both of them also shows they are identical:
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
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")
And if we plot them, they are very different
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
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!