Implementing the mathematical formula for rarefaction to measure richness in R (CC197)
Channel: Riffomonas Project
Date: 2022-03-21

Did you know that there's a mathematical formula to measure richness by rarefaction? It leverages all sorts of concepts that we rarely think about, but are important to appreciate to full understand rarefaction. In this episode we'll use the R factorial, combn, choose, and lchoose functions to get an exact solution for the richness of a community rarefied to a specific sampling depth. Along the way we'll also discuss the power of working with logrithms. I'll show how to synthesize and visualize the data using tools from base R, dplyr, ggplot2 and other tidyverse packages.

You can find my blog post for this episode at https://www.riffomonas.org/code_club/2022-03-21-rarefaction-math. The data were generated in our Kozich et al. 2013 paper (http://doi.org/10.1128/AEM.01043-13) using samples from the Schloss et al. 2012 paper (http://doi.org/10.4161/gmic.21008).

#rarefation #math #R #Rstudio #Rstats

Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at https://shop.riffomonas.org/youtube to get practice problems, tips, and insights.

If you're interested in taking an upcoming 3 day R workshop be sure to check out our schedule at https://riffomonas.org/workshops/

You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: https://www.riffomonas.org/minimalR/
General data: https://www.riffomonas.org/generalR/

0:00 Calculating the exact rarefied richness
2:30 dplyr review
5:21 The math of rarefaction
9:01 Factorials and choosing in R
13:13 Working with logrithms
19:24 Creating and implementing a rarefy function
20:42 Comparing rarefied and non-rarefied data