Hy4m / linkET

Everything is Linkable
145 stars 39 forks source link

Caused by error in `spec_dist()`: ! could not find function "spec_dist" #13

Closed BenPonBiobrain closed 1 year ago

BenPonBiobrain commented 1 year ago

Hi,

Thank you for this great package!

I use your code example (linkET v.0.07.1) below:

mantel_test(varespec, varechem, spec_select = list(spec01 = 1:5, spec02 = 6:12)) 'mantel_test()' using 'bray' dist method for 'spec'. 'mantel_test()' using 'euclidean' dist method for 'env'.

which applies bray to spec.

However, on my 16S amplicon dataset, I would like to manually specify the distance for spec and chem becaue by default it always applies euclidean distances to my species data but I want to use Bray-Curtis.

In the help manual to mantel_test(), I found that you can specify spec_dist = and env_dist =, however, the function dist_func() does not seem to offer the usually applied distances found in e.g. vegan::vegdist(method = "bray").

Could you please provide an example of how to specify e.g. Bray-Curtis using dist_func(). Also when looking up the help page for dist_func() one gets redirected to gdist(), without a clear explanation of how they relate and are supposed to be implemented in the mantel_test().

Thank you for helping and for sharing your expertise!

Hy4m commented 1 year ago

I'm guessing that the reason your 16s data always chooses Euclidean distance is because the data doesn't meet the requirements. As far as I know, bray distance requires that the sum of any row of data does not equal 0. To verify this, you can try the following code:

library(linkET)
## Please replace with your data
data(varespec, package = "vegan")
data(varechem, package = "vegan")
mantel_test(varespec, varechem,
            spec_select = list(spec01 = 1:5, spec02 = 6:12),
            spec_dist = dist_func(.FUN = "vegdist", method = "bray"))

If my previous guess is correct, an error will be reported in the above case, mainly due to missing values.

Finally, please forgive my poor English, and it is for this reason that the help documentation for this package is very, very bad.

BenPonBiobrain commented 1 year ago

I double checked my dataset and it was indeed as you said, got an error.

I removed one Station that was not present in the other dataset and it works fine 😊

Thank you very much for the fast reply and help.

I wish you a good day.

Best regards,

Ben

From: Hou Yun @.> Reply to: Hy4m/linkET @.> Date: Thursday, 30. March 2023 at 14:34 To: Hy4m/linkET @.> Cc: Benjamin Pontiller @.>, Author @.***> Subject: Re: [Hy4m/linkET] Caused by error in spec_dist(): ! could not find function "spec_dist" (Issue #13)

I'm guessing that the reason your 16s data always chooses Euclidean distance is because the data doesn't meet the requirements. As far as I know, bray distance requires that the sum of any row of data does not equal 0. To verify this, you can try the following code: library(linkET)

Please replace with your data

data(varespec, package = "vegan") data(varechem, package = "vegan") mantel_test(varespec, varechem,             spec_select = list(spec01 = 1:5, spec02 = 6:12),             spec_dist = dist_func(.FUN = "vegdist", method = "bray")) If my previous guess is correct, an error will be reported in the above case, mainly due to missing values.

Finally, please forgive my poor English, and it is for this reason that the help documentation for this package is very, very bad.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

Hy4m commented 1 year ago

For the distance method, I added a way to set directly through the method name, see the source code for details NEW PR.

Here is an example:

library(vegan)
data("varespec")
data("varechem")
mantel_test(varespec, varechem,
            spec_select = list(spec01 = 1:5, spec02 = 6:12),
            env_select = list(env01 = 1:5, env02 = 6:10, env03 = 11:14),
            spec_dist = "euclidean",
            env_dist = "euclidean")

Finally, thank you for your feedback.

Best Regards Hou Yun