Data and Libraries

Libraries and data were loaded/cleaned. Knitr was added as a package to create the tables.

library(readxl)
library(tidyverse)
library(knitr)

cary<-read_xls("Transect_Data_Set/temp.namerica/CARY.xls")
hbm<-read_xls("Transect_Data_Set/temp.namerica/HEUSTOBM.xls")

ccary<- cary %>%
  select(-voucher...5,-voucher...6,-voucher...7,-voucher...8,-voucher...9,    
         -voucher...10,-voucher...11,-voucher...12,-Liana, -"N(Ind.)") %>%      
  pivot_longer(cols = starts_with("Stemdbh"), 
               values_to = "Stemdbh") %>%
  filter(!is.na(Stemdbh)) %>%
  select(-name)


chbm<- hbm %>%
  select(-voucher...5,-voucher...6,-voucher...7,-voucher...8,-voucher...9,
         -voucher...10,-voucher...11,-voucher...12,-Liana, -"N(Ind.)") %>%
  pivot_longer(cols = starts_with("Stemdbh"), 
               values_to = "Stemdbh") %>%
  filter(!is.na(Stemdbh)) %>%
  select(-name)

Preparation for Calculations

Preparing for the calculations that come before the actual indices such as the D value for each species and line and calculations that come before the H value

calcD<- function(n,N){
  (n/N)^2
}

n_count <- ccary %>%       #indiviuals per species         CARY 
  group_by(Line, Species) %>%
  summarize(n = n()) %>%
  ungroup()

N_count <- ccary %>%    #total individuals per line
  group_by(Line) %>%
  summarize(N = n()) %>%
  ungroup()

nandN<-left_join(n_count,N_count, by=c("Line"="Line"))

n_count2 <- chbm %>%       #indiviuals per species          HEUSTO
group_by(Line, Species) %>%
  summarize(n = n()) %>%
  ungroup()

N_count2 <- chbm %>%    #total individuals per line
  group_by(Line) %>%
  summarize(N = n()) %>%
  ungroup()

nandN2<-left_join(n_count2,N_count2, by=c("Line"="Line"))

Calculations for Transects

The calculations for D, n/N, etc. for each species and line which was then used in the meanD dataframes to get indices for each transect line. Tables were also created for each site.

withD <- nandN %>%
  mutate(D = calcD(n,N)) %>%               #D calc                                   
  mutate(ndivN= n/N) %>%                   #n/N
  mutate(lnndivN= log(n/N)) %>%            #ln(n/N)
  mutate(befH= ndivN * lnndivN)            # negative H


meanD<- withD %>%                      #CARY site indices per transect
  group_by(Line) %>%
  summarize(meanD= round(mean(D),3),
            meanbefH= round(mean(befH),3),
            totspecies= n_distinct(Species)) %>%
  mutate(Index_of_Div= round(1-meanD,3)) %>%
  mutate(Recip_Index= round(1/meanD,3)) %>%
  mutate(ESimp= round(Recip_Index/totspecies,3)) %>%
  mutate(H= round(-1 * meanbefH,3)) %>%
  mutate(EShan= round(H/log(totspecies),3)) %>%
  arrange(as.numeric(Line)) %>%
  mutate(Site="Cary") %>%
  select(-meanbefH)

withD2 <- nandN2 %>%
  mutate(D = calcD(n,N)) %>%   
  mutate(ndivN= n/N) %>%
  mutate(lnndivN= log(n/N)) %>%
  mutate(befH= ndivN * lnndivN)    


meanD2<- withD2 %>%                    #HEUSTO site indices per transect
  group_by(Line) %>%
  summarize(meanD= round(mean(D),3),
            meanbefH= round(mean(befH),3),
            totspecies= n_distinct(Species)) %>%
  mutate(Index_of_Div= round(1-meanD,3)) %>%
  mutate(Recip_Index= round(1/meanD,3)) %>%
  mutate(ESimp= round(Recip_Index/totspecies,3)) %>%
  mutate(H= round(-1 * meanbefH,3)) %>%
  mutate(EShan= round(H/log(totspecies),3)) %>%
  arrange(as.numeric(Line)) %>%
  mutate(Site="Heusto B/M") %>%
  select(-meanbefH)

carytable<-kable(meanD, format="html")
kable(meanD, format="html")
Line meanD totspecies Index_of_Div Recip_Index ESimp H EShan Site
1 0.040 6 0.960 25.000 4.167 0.266 0.148 Cary
2 0.018 10 0.982 55.556 5.556 0.201 0.087 Cary
3 0.028 7 0.972 35.714 5.102 0.256 0.132 Cary
4 0.017 9 0.983 58.824 6.536 0.224 0.102 Cary
5 0.069 4 0.931 14.493 3.623 0.332 0.239 Cary
6 0.097 4 0.903 10.309 2.577 0.288 0.208 Cary
7 0.041 6 0.959 24.390 4.065 0.261 0.146 Cary
8 0.021 9 0.979 47.619 5.291 0.210 0.096 Cary
9 0.031 6 0.969 32.258 5.376 0.289 0.161 Cary
10 0.022 8 0.978 45.455 5.682 0.236 0.113 Cary
heustobmtable<- kable(meanD2, format="html")
kable(meanD2, format="html")
Line meanD totspecies Index_of_Div Recip_Index ESimp H EShan Site
1 0.053 5 0.947 18.868 3.774 0.287 0.178 Heusto B/M
2 0.032 6 0.968 31.250 5.208 0.283 0.158 Heusto B/M
3 0.048 5 0.952 20.833 4.167 0.301 0.187 Heusto B/M
4 0.086 4 0.914 11.628 2.907 0.303 0.219 Heusto B/M
5 0.031 6 0.969 32.258 5.376 0.291 0.162 Heusto B/M
6 0.033 6 0.967 30.303 5.051 0.283 0.158 Heusto B/M
7 0.055 6 0.945 18.182 3.030 0.238 0.133 Heusto B/M
8 0.032 8 0.968 31.250 3.906 0.213 0.102 Heusto B/M
9 0.116 3 0.884 8.621 2.874 0.360 0.328 Heusto B/M
10 0.030 8 0.970 33.333 4.167 0.210 0.101 Heusto B/M

Calculations for Sites

Joining the two two meanD tables to get the average index values per site. Made a table from the dataframe.

avgsite<- meanD %>%              #table with indices for the two sites
 rbind.data.frame(meanD2) %>%
  group_by(Site) %>%
  summarize(D=round(mean(meanD),3),
  "1-D"=round(mean(Index_of_Div),3),
  "D'"=round(mean(Recip_Index),3),
  ESimpson=round(mean(ESimp),3),
  H=round(mean(H),3),
  EShannon=round(mean(EShan),3))
  

avgsitetable<- kable(avgsite, format="html") 
kable(avgsite, format="html") 
Site D 1-D D’ ESimpson H EShannon
Cary 0.038 0.962 34.962 4.798 0.256 0.143
Heusto B/M 0.052 0.948 23.653 4.046 0.277 0.173