Header image  
INVERTEBRATE ECOLOGY  
line decor
      | ualberta.ca   | Faculty of Agricultural, Environmental and Life Sciences | Renewable Resources
line decor
 
 
 
 

 
Individual Based Rarefaction using R-package
Rarefaction is a method for comparing species richness between treatments after standardizing to account for sampling effort. More information is available in Buddle et al. (2005).

Overview

I) Installing R-package and vegan package from CRAN
II) Preparing Data and importing into R
III) Rarefaction in R
IV) Hints and tricks
V) Notes and Problems
VI) References

I) Installing R-package and vegan package from CRAN

1) Download and install the setup file from the r-project website
    (at the time of writing the the setup file was available here)

2) Open R and install the mvpart package by selecting Install package(s) from CRAN...

image2

3) Select vegan from the list and click OK

II) Preparing Data and importing into R

1) In Excel create a table with treatments (each line on the rarefaction plot) as row headings and species as column headings.  (If your data is opposite (species in rows, treatments in columns) see number 2 in the hints and tricks section).
2)Save the file as a .csv (comma separated values), by choosing "Save as" from the File menu, and change Save as type to "CSV(Comma delimited)"

You are now ready to import your data into R
3) Open the R program
4) Change the working directory to where you saved you .csv file from step 2 by selecting "Change dir" from the file menu and browsing to the proper directory
5) In order to import your file into R you need to use the read.csv command.  To find out more about this command type "?read.csv" without the quotation marks at the pompt.

To use the read.csv command type:
>name<- read.csv("filename.csv", row.names=1)
      
name: the name of the file in R
       filename: the name you called your file in excel
       row.names=1, use this if the first column of your data are the names of your rows (i.e."Sample 1")

III)Rarefaction in R

1) The rarefaction function is basically a loop script of the rarefy function in the vegan package.  Download the rarefaction function by RIGHT clicking here, and save the target to a folder.  I put mine in a folder called functions in my R folder eg. C:\Program Files\R\functions.
2) Load the vegan package by selecting "Load Package..." from the package menu. Then select "vegan" and click ok.  Alternatively you can type >library(vegan)
3) Source the rarefaction function by typing
        >source("C:\\Program Files\\R\\functions\\rarefaction.txt")  #or wherever you saved it#
4)The rarefaction function is rarefaction(x, c(subsample))
                where     x=the datamatrix
                and         subsample=the subsample sizes to use separated by commas

Try this example:
1) Download the EMEND data file EMEND.csv
2) Open R and set working directory to the location of the EMEND.csv file you just saved (File>Change Dir...)
3) Type the commands
>library(vegan)
>source("C:\\Program Files\\R\\functions\\rarefaction.txt")
>EMEND<-read.csv("EMEND.csv", row.names=1)
>rarefaction(EMEND, c(0,20,40,60,80,100,200,300,400,500,600,700,800,900,1000,1500,2000,2500))

5) The rarefaction function creates 2 new data matrices;  
richness
- treatments as columns and subsample size as rows with mean species richness as the value
richness.error - the same as richness but with SE as the value.
Type "richness" or "richness.error" at the command line to see these matrices (without the quotation marks).
6) Export the richness and/or richness.error matrices with the write.csv command
        >write.csv(richness, file="EMENDrichness.csv")
        >write.csv(richness.error, file="EMENDerror.csv")
7) Open these files in your favourite graphing program (eg. Excel, Sigmaplot) and remove any values of richness once the max richness is reached
8) Make pretty graphs.

IV) Hints and tricks

1) Calculate the end points of each treatment (row) and include those as your subsample sizes
                    >rarefaction(EMEND, c(0,20,40,60,80,100,200,300,400,500,540,585,600,642,700,800,900,945,1000,1385,1500,1650,2000,2440,2447))
2) If your data has species in rows and treatments in columns use the t(x) command
                    >rarefaction(t(x), c(subsample))

V) Notes and Problems

 

VI) References

Buddle, C.M., Beguin, J., Bolduc, E., Mercado, A., Sackett, T.E., Selby, R.D., Varady-Szabo, H., and Zeran, R.M. 2005. The importance and use of taxon sampling curves for comparative biodiversity research with forest arthropod assemblages. Can. Entomol. 137: 120-127.