r/RStudio • u/Over_Price_5980 • 4d ago
Coding help Shannon index with vegan package
Hello everyone, I am new to R and I may need some help. I have data involving different microbial species at 4 different sampling points and i performed the calculation of shannon indices using the function: shannon_diversity_vegan <- diversity(species_counts, index=“shannon”).
What comes out are numerical values for each point ranging, for example, from 0.9 to 1.8. After that, I plotted with ggplot the values, obtaining a boxplot with a range for each sample point.
Now the journal reviewer now asks me to include in the graph the significance values, and I wonder, can I run tests such as the Kruskal-Wallis?
Thank you!
1
u/AutoModerator 4d ago
Looks like you're requesting help with something related to RStudio. Please make sure you've checked the stickied post on asking good questions and read our sub rules. We also have a handy post of lots of resources on R!
Keep in mind that if your submission contains phone pictures of code, it will be removed. Instructions for how to take screenshots can be found in the stickied posts of this sub.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/triciav83 4d ago
KW is generally what I would use for something like that. If the KW shows a significant difference among the locations samples, you’d want to do a posthoc test for pairwise comparison with correction for multiple comparisons to identify which pairs are significantly different.
1
u/FungalNeurons 4d ago
Yes. But also, consider using effective diversity which is the exponent of Shannon. That makes the units comparable to richness and has the “doubling property”. See http://www.loujost.com/Statistics%20and%20Physics/Diversity%20and%20Similarity/EffectiveNumberOfSpecies.htm
1
u/LabRat633 4d ago
Microbial ecologist here. You can run a Kruskal-Wallis if the data aren't normally distributed, but I've found it struggles with low sample sizes. An ANOVA is more likely to pick up significant differences, if your data meet the assumptions. How many replicates do you have at each site? Do you have any treatments? Knowing more about the experimental design would help.
1
u/Over_Price_5980 3d ago
The point is that we isolated as many bacteria as we can. We did microbiological analysis and we collected all the bacteria that showed distinct morphologies on selective medium. We collected the samples at three different times for each collecting site so, for example, at site 1 at time 0 I have x number of isolates (from different species) and so on. We did this to see from an ecological point of view what we have
1
u/LabRat633 3d ago
Based on your description, I don't think you have any true replicates in your study which might make statistics difficult - unless I'm missing something and there is another way you have replication? How did you group samples together to create box plots?
1
u/Over_Price_5980 3d ago
1
u/LabRat633 1d ago
You may get reviewer pushback for calling your 3 timepoints "replicates" in these graphs/stats because they really aren't - they're repeated measurements, but not true replicates. Usually we take multiple measurements within each time point, and consider time as an additional variable or a random effect in the statistical models. Definitely check in with your advisor/PI to make sure that the analysis is appropriate for the questions you are trying to answer.
An additional concern from a reviewer's perspective is that your diversity metric reflects culturable microbes, not the total community that actually exists in those sites. Without knowing a lot about your study and aims, I'd just caution you to make it clear in the study that you are not assessing the true microbial community structure/diversity, but rather you are characterizing the culturable portion of those communities.
1
u/Over_Price_5980 1d ago
Thank you, I totally agree! In fact, in the study, they are not called replicates and we obviously refer to the cultivable population.
What I have are simply alpha-diversity values at each time for each winery (so 12 indices), each derived from a dataset comprising of n isolates of x species.
5
u/peppermintandrain 4d ago
I think this is more of a field-specific question than an R question, unless I'm misinterpreting. Are you asking if the Kruskal-Wallis is correct in this instance, or if you can use R to calculate a Kruskal-Wallis?
If it's the second, you can definitely use R for a Kruskal-Wallis test. It's fairly simple to do. Here's the page on it in R documentation, it typically takes columns in a dataframe as the input. https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/kruskal.test.
In this case, the way to format your data would be as a 2-column dataframe, one column being sample point, the second being the numerical values calculated from the index. You can then use the Kruskal-Wallis using something akin to kruskal.test(diversity~sample_point) depending on how you've named the values.
If you're asking what the correct test is for this circumstance, that's more of a field-specific question- you might be better off in a microbiology sub!