Skip to content

Commit

Permalink
Use Chao et al. 2014 approach for rarefaction and extrapolation
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMay committed Mar 27, 2019
1 parent 420b0ad commit e3c9414
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
12 changes: 12 additions & 0 deletions ISAR_DATA/alpha_Sn_frag.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"";"Site";"m";"order";"qD";"qD.LCL";"qD.UCL";"SC";"SC.LCL";"SC.UCL"
"1";1;340;0;20,903;10,512;31,295;0,982;0,953;1,011
"2";2;340;0;25,065;16,635;33,495;0,963;0,936;0,991
"3";3;340;0;23,861;19,291;28,43;0,981;0,965;0,997
"4";4;340;0;16,88;9,697;24,063;0,987;0,964;1,01
"5";5;340;0;15,8315;7,58;24,0835;0,9965;0,98;1,014
"6";6;340;0;16,4325;9,805;23,0605;0,9805;0,9595;1,0015
"7";7;340;0;24,8795;19,673;30,0855;0,9845;0,9685;1,0015
"8";8;340;0;27,4225;21,456;33,3895;0,9715;0,9465;0,9965
"9";9;340;0;31,5666666666667;23,2226666666667;39,911;0,971;0,940666666666667;1,00033333333333
"10";10;340;0;30,664;19,0633333333333;42,2653333333333;0,958;0,917;0,998666666666667
"11";11;340;0;21,6973333333333;16,6803333333333;26,7133333333333;0,975;0,958;0,992666666666667
12 changes: 12 additions & 0 deletions ISAR_DATA/gamma_frag.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"";"m";"order";"qD";"qD.LCL";"qD.UCL";"SC";"SC.LCL";"SC.UCL";"Site"
"V1.6";340;0;20,903;9,111;32,696;0,982;0,951;1,013;1
"V2.6";340;0;25,065;18,73;31,4;0,963;0,939;0,987;2
"V3.6";340;0;23,861;19,388;28,334;0,981;0,966;0,997;3
"V4.6";340;0;16,88;10,612;23,147;0,987;0,967;1,008;4
"V5.6";340;0;22,361;16,46;28,261;0,984;0,962;1,007;5
"V6.3";340;0;17,225;14,321;20,128;0,986;0,978;0,993;6
"V7.3";340;0;29,619;25,932;33,305;0,968;0,959;0,977;7
"V8.3";340;0;29,532;25,894;33,17;0,967;0,959;0,975;8
"V9.3";340;0;34,35;31,431;37,27;0,962;0,954;0,969;9
"V10.3";340;0;34,669;30,829;38,509;0,959;0,949;0,97;10
"V11.3";340;0;24,995;22,27;27,721;0,969;0,962;0,976;11
33 changes: 28 additions & 5 deletions R_scripts/2_calculate_Sn_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
# load transect level data and iNEXT

library(iNEXT)
frag_abund <- read_csv("Desktop/ISAR_DATA/datasets/forest_fragments_data.csv")
library(tidyverse)

# please set all path relative to the GitHub repo folder
# to do that please do the following in RStudio:
# Menu Session --> Set working directory --> To project directory
work_dir <- getwd()

frag_abund <- read_csv("ISAR_DATA/datasets/forest_fragments_data.csv")

# The file is called forest fragments, but the species names are really familier to me.
# Apparently this is data from my project in Israel. Is this correct???

# Transpose data to fit iNEXT data format requirement
Site_names <- frag_abund$Site
Expand All @@ -15,10 +25,19 @@ frag_abund$Site <- NULL
t_frag_abund<- t(frag_abund)
t_frag_abund <- as.data.frame(t_frag_abund)

# Implement approach by Chao et al. 2014
n_sites <- rowSums(frag_abund)

r <- 2

max_n <- max(n_sites)
min_n_r <- min(r * n_sites)
n <- max(max_n, min_n_r)
# --------------------

# Get average N values where Sn will be interpolated or extrapolated
#from local rarefaction curves (one curve per transect per fragment)
n <- round(mean(rowSums(frag_abund)))
#n <- round(mean(rowSums(frag_abund)))

m <- c(10,20,n)

Expand All @@ -43,11 +62,13 @@ average_Sn_alpha <- ext_dat_a %>%
summarise_all(mean)

# Save iNEXT Sn estimates and calculate average Sn values per fragment
write.csv2(average_Sn_alpha, "/Users/leanagooriah/desktop/ISAR_DATA/alpha_Sn_frag.csv")
outfile <- paste(work_dir, "/ISAR_DATA/alpha_Sn_frag.csv", sep = "")
write.csv2(average_Sn_alpha, outfile)


###### GAMMA SN ESTIMATES #####
frag_abund <- read_csv("Desktop/ISAR_DATA/datasets/forest_fragments_data.csv")

frag_abund <- read_csv("ISAR_DATA/datasets/forest_fragments_data.csv")

# Calculate summed up abundance
frag_sum <- frag_abund %>%
Expand All @@ -73,6 +94,8 @@ ext_dat_g <- subset(ext_dat_g, m == n)
ext_dat_g$method <- NULL
ext_dat_g$Site <- Site_names
# Save iNEXT gamma Sn estimates
write.csv2(ext_dat_g, "/Users/leanagooriah/desktop/ISAR_DATA/gamma_frag.csv")

outfile <- paste(work_dir, "/ISAR_DATA/gamma_frag.csv", sep = "")
write.csv2(ext_dat_g, outfile)


0 comments on commit e3c9414

Please sign in to comment.