This is a quick example for using the individual functions in the patches package.
All metrics are based on Wang and Loreau (2014, Ecology Letters). Below is a schematic for how they are all related, and the equations used in the functions.
Load a bunch of packages, then install patches
. Also read in a test data set.
# Load relevant packages # install.packages(c("dplyr", "plyr", "reshape2", "synchrony", "devtools")) require(plyr) require(dplyr) require(reshape2) require(synchrony) require(devtools) # Install package from GitHub devtools::install_github("atredennick/patches") require(patches) # Read in data setwd("/Users/atredenn/Dropbox/Patches/") species_data_kbs <- read.csv("./Data sets/AllSpData_02282015.csv")%>% filter(site_code=="KBS") %>% filter(treatment=="T0F0")
# Start with species synchrony in each patch phi <- species_synchrony(D = species_data_kbs) print(phi)
First column is the plot id, second is species synchrony in that plot.
CVji <- ind_spp_var(D=species_data_kbs) # look at just the head...there are num_spp*num_plots lines head(CVji)
Note that species that only show up once in the time series have the same CV. Here's an example of why that happens...
obs_anpp <- c(1:10) num_years <- 10 for(i in 1:length(obs_anpp)){ ts <- numeric(num_years) ts[1] <- obs_anpp[i] cv <- sd(ts)/mean(ts) print(cv) }
So, regardless of the actual value, if there is only one observation, then the CVs are always equal.
CVspp_i <- avg_spp_var(D = species_data_kbs) # Returns one value per plot print(CVspp_i)
CVi_sq <- community_var(D = species_data_kbs) # Returns one value per plot print(CVi_sq)
CV_L <- alpha_var(D = species_data_kbs) # Returns one value print(CV_L)
B_1 <- beta_var(D = species_data_kbs) # Returns one value print(B_1)
CV_M <- gamma_var(D = species_data_kbs) # Returns one value print(CV_M)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.