CmlMagneville / mFD

:package: A Computation of Functional Spaces and Functional Diversity Indices
https://cmlmagneville.github.io/mFD/
GNU General Public License v2.0
24 stars 5 forks source link

Different FRic by mFD and FD #30

Closed zhangzhixin1102 closed 2 years ago

zhangzhixin1102 commented 2 years ago

Dear mFD authors,

First of all, thank you for developping such a useful R package. I am new to functional diversity and really benefit a lot after going through your workflow.

I tried to calculate functional diversity such as FRic using mFD and FD R packages. I found that the two packages provide different results. I am wandering which one is correct? Do I miss some important parameter settings in the mFD::alpha.fd.multidim() function? Please check the following R scripts for a reproducible example. Thank you for your kind help.

Best,

Zhixin

#################################### ######## 1 load R packages #################################### library(mFD)

#################################### ######## 2.1 load species x trait #################################### data("fruits_traits", package = "mFD")

######## Remove fuzzy traits in this tutorial: fruits_traits <- fruits_traits[ , -c(6:8)]

######## data frame summarizing the type of each trait fruits_traits_cat <- data.frame(names(fruits_traits), c("O","N","O","O","Q")) colnames(fruits_traits_cat) <- c("trait_name", "trait_type") fruits_traits_cat

#################################### ######## 2.2 load site x species dataframe #################################### data("baskets_fruits_weights", package = "mFD") ######## Summary of the site * species dataframe: asb_sp_fruits_summ <- mFD::asb.sp.summary(asb_sp_w = baskets_fruits_weights)

######## Species occurrences asb_sp_fruits_summ$asb_sp_occ

#################################### ######## 3 Computing distances between species based on functional traits #################################### sp_dist_fruits <- 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) as.matrix(sp_dist_fruits)[1:2, 1:2]

#################################### ######## 4. Computing functional spaces & their quality #################################### fspaces_quality_fruits <- mFD::quality.fspaces( sp_dist = sp_dist_fruits, maxdim_pcoa = 10, deviation_weighting = "absolute", fdist_scaling = FALSE, fdendro = "average")

fspaces_quality_fruits$quality_fspaces sp_faxes_coord_fruits <- fspaces_quality_fruits$"details_fspaces"$"sp_pc_coord"

#################################### ######## 5. Compute functional diversity indices & plot them #################################### FRic1 <- mFD::alpha.fd.multidim( sp_faxes_coord = sp_faxes_coord_fruits[ , c("PC1", "PC2", "PC3", "PC4")], asb_sp_w = asb_sp_fruits_summ$asb_sp_occ, ind_vect = c("fric"), scaling = TRUE, check_input = TRUE, details_returned = TRUE)

######## return functional diversity by mFD FRic1$functional_diversity_indices$fric ######## [1] 0.162830681 0.162830681 0.162830681 0.007880372 0.007880372 0.147936148 ######## [7] 0.147936148 0.036480112 0.036480112 0.025774304

FRic2 <- FD::dbFD(sp_faxes_coord_fruits[ , c("PC1", "PC2", "PC3", "PC4")], asb_sp_fruits_summ$asb_sp_occ) FRic2$FRic

######## basket_1 basket_2 basket_3 basket_4 basket_5 basket_6 basket_7 ######## 4.6925609 4.6925609 4.6925609 0.2271017 0.2271017 4.2633206 4.2633206 ######## basket_8 basket_9 basket_10 ######## 1.0513077 1.0513077 0.7427807

CmlMagneville commented 2 years ago

Dear Zhixin,

In the mFD package, FRic values are standardised by the global FRic value including all species from all the studied assemblages. You thus have values between 0 and 1 which represent the proportion of the global convex-hull filled by the studied assemblage. Using de dbFD package, you have to precise that FRic values have to be standardised using the stand.FRic =TRUE` argument. If you run: FRic2 <- FD::dbFD(sp_faxes_coord_fruits[ , c("PC1", "PC2", "PC3", "PC4")], asb_sp_fruits_summ$asb_sp_occ, stand.FRic = TRUE) Then you will have the same values usingmFDandFD` packages.

Best,

Camille

zhangzhixin1102 commented 2 years ago

Dear Camille,

Thank you for your kind reply.

I understand that we can standardise the FRic and get the identical results by using FD::dbFD() and mFD::alpha.fd.multidim().

In my study, I have a huge number of sites (in other words, the site x species matrix is large). To reduce computation time and avoid memory issue, I would like to split my data in different subsets (e.g., data1, data2, etc). So my question is: when I calculated FRic values separately for each dataset using mFD::alpha.fd.multidim() , are the global FRic values in different datasets (data1, data2, etc) the same? If the same, then we can directly compare FRic in different datasets; but if different, then I would like not to standardise the results.

So, if I set stand.FRic = FALSE in FD::dbFD(), how can I still get the same results by using mFD::alpha.fd.multidim()? I tried the scaling = FALSE, but it does not give the same results.

Sorry for my strange question and look forward to your feedback.

Have a nice day.

Zhixin

CmlMagneville commented 1 month ago

[replied by email on 11/2022][copied-paste here if it can help someone else]

Ok I understand your question this time, sorry for my misunderstanding. In order to be able to compare FRic values (if you standardise or not), you have to compute them in the same functional space. Thus all the steps used to build functional space must be realised with the global dataset. Then you can use the mFD::alpha.fd.multidim() function with a subset of the species assemblage matrix gathering only some of your assemblages. The only thing is that when building the subset of the species assemblages matrix, all species must be present in at least one assemblage (but you will have a clear error message if it is not the case).