mooreryan / divnet-rs

A fast implementation of DivNet
https://mooreryan.github.io/divnet-rs-book/
Apache License 2.0
3 stars 0 forks source link

divnet-rs analyses other than Shannon diversity? #3

Closed LTibbs closed 3 years ago

LTibbs commented 3 years ago

Ryan,

Thanks so much for your work on this project, I am planning to use divnet-rs rather than DivNet on my large dataset.

Your instructions show how to calculate Shannon diversity from divnet-rs output, but DivNet itself also has other outputs. A typical DivNet output is:

An object of class 'diversityEstimates' with the following elements:
  -  shannon 
  -  simpson 
  -  bray-curtis 
  -  euclidean 
  -  shannon-variance 
  -  simpson-variance 
  -  bray-curtis-variance 
  -  euclidean-variance 
  -  X 
  -  fitted_z 

Is divnet-rs able to provide all of these results just like DivNet can, or only the Shannon diversity? If so, how can we access these other results?

I think I can at least get the Simpson diversity results by replacing DivNet::shannon_true with DivNet::simpson_true in your script 3_import_divnet_rs_data.R, but let me know if that assumption is not correct.

Thanks!


Edit by mooreryan: LTibbs provided this code used to calculate some other diversity measures. Feel free to check it out!!

mooreryan commented 3 years ago

Hey, thanks for your question.

Calculating diversity measures

You can use the output from divnet-rs to compute other diversity measures than the one shown in the tutorial. To do so, it goes something like this:

  1. Calculate the diversity measure on replicate 0. Rep 0 is the divnet diversity estimate for the actual data.
  2. Calculate the diversity measure on replicates 1 - N, where N is the number of replicates you ran. These relative abundances are the estimates for the bootstrap replicates.
  3. Take the variance (or standard deviation) of the diversity values calculated in step 2. These become your error estimates for the diversity estimate calculated in step 1.

You're correct in that you could swap simpson_true for shannon_true in that example. There's nothing special about those functions though...in fact, you could calculate the either method yourself "by hand". That specific example code could be adapted to use any diversity measure that takes a vector of relative abundances.

Getting the beta diversity is a bit more involved, but you can use the code here to guide you in calculating in the way the DivNet R package calculates diversity measures.

More info

In case you didn't see, here is a link to the documentation for divnet-rs. Also, you may find this discussion on using divnet-rs output for breakaway and hypothesis testing.

Let me know if you have any more questions. Thanks!!

LTibbs commented 3 years ago

Thanks, I was able to calculate the Bray-Curtis and Euclidean components of the DivNet output based on your response.

LTibbs commented 2 years ago

Ryan,

I got an email from someone requesting the code I used to calculate Bray-Curtis distance as addressed in this issue, so I posted it in my GitHub to share with them. I wanted to share it with you as well in case you would like to include it in future tutorials. Here it is: https://github.com/LTibbs/tardigrade_microbiome/blob/main/code/beta_diversity.R .

--Laura

mooreryan commented 2 years ago

Very cool, thanks for posting that here. Truthfully, I haven't updated the docs yet, but I have been pointing people to the discussions on this and other issues, so I'm sure it will be helpful for future users!! I will also edit the original issue post so it's more visible to people who come to this issue.

Thanks!!! :sparkles: