Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Commit

Permalink
Revised electivity analysis
Browse files Browse the repository at this point in the history
Updated electivity analysis to use individual plots. Reduced sample size. TODO: Analaysis of tree versus interspace without dead trees included
  • Loading branch information
flakesw committed Nov 5, 2018
1 parent b578d61 commit 0746d95
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .Rproj.user/EAEB7255/sources/prop/70A12DA3
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cursorPosition" : "100,41",
"scrollLine" : "77",
"cursorPosition" : "266,1",
"scrollLine" : "257",
"tempName" : "Untitled1"
}
10 changes: 5 additions & 5 deletions .Rproj.user/EAEB7255/sources/s-94DF0EFB/EAD5E16F
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "3864997688",
"hash" : "0",
"id" : "EAD5E16F",
"lastKnownWriteTime" : 1541445482,
"last_content_update" : 1541445482398,
"lastKnownWriteTime" : 1541455209,
"last_content_update" : 1541455209512,
"path" : "C:/Users/Sam/Google Drive/Projects/MS Thesis/Understory/understory_electivity.R",
"project_path" : "understory_electivity.R",
"properties" : {
"cursorPosition" : "100,41",
"scrollLine" : "77",
"cursorPosition" : "266,1",
"scrollLine" : "257",
"tempName" : "Untitled1"
},
"relative_order" : 3,
Expand Down
66 changes: 42 additions & 24 deletions .Rproj.user/EAEB7255/sources/s-94DF0EFB/EAD5E16F-contents
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ for(i in 1:n_quads_occ){

# import and recode microsite data
ms <- read.csv("./raw data/microsite.csv")
ms$ms <- ifelse(ms$Microsite %in% c("PI", "JI", "CI"), "Live Inner",
ifelse(ms$Microsite %in% c("PO", "JO", "CO"), "Live Outer",
ms$ms <- ifelse(ms$Microsite %in% c("PI", "JI", "CI", "PO", "JO", "CO"), "Live",
# ifelse(ms$Microsite %in% c("PO", "JO", "CO"), "Live Outer",
ifelse(ms$Microsite %in% c("PI(S)", "PO(S)", "JI(S)", "JO(S)", "CI(S)", "CO(S)"), "Dead",
ifelse(ms$Microsite =="LOG", "Log",
ifelse(ms$Microsite == "I", "Inter", NA)))))
ifelse(ms$Microsite == "I", "Inter", NA))))#)
ms[ms$Transect == "e", "Transect"] <- "E"
ms[ms$Transect == "s", "Transect"] <- "S"
ms[ms$Transect == "w", "Transect"] <- "W"
Expand All @@ -98,18 +98,6 @@ ms[ms$Plot == "NPElectricEel120", "Plot"] <- "NPELECTRICEEL120"

ms$unique_quad <- paste0(ms$Plot, ms$Transect, ms$Meter)

unique(ms$Plot)[!(unique(ms$Plot) %in% unique(daub$Plot))]
unique(daub$Plot)[!(unique(daub$Plot) %in% unique(ms$Plot))] #WHIS64240

#how many quadrats are messed up?
table(ms[!(ms$unique_quad %in% unique(daub$unique_quad)), "Plot"])[table(ms[!(ms$unique_quad %in% unique(daub$unique_quad)), "Plot"]) > 0]
#SPR1575 (7 quads), TOI1577360
table(daub[!(daub$unique_quad %in% unique(ms$unique_quad)), "Plot"])/11 #same as above, plus WHIS64240

#which quadrats are messed up?
unique(ms[!(ms$unique_quad %in% unique(daub$unique_quad)), "unique_quad"])
unique(daub[!(daub$unique_quad %in% unique(ms$unique_quad)), "unique_quad"])

#get total cover for each plot
total_cover <- aggregate(daub$Midpoint.value, by = list(daub$Plot, daub$Cover.type), FUN = sum)

Expand All @@ -126,13 +114,14 @@ for(i in 1:length(unique(ms$Plot))){

plots_to_use <- unique(ms$Plot)[plots_to_use_dead & plots_to_use_live]

#-----------------------------------------------------------------------------------------------

grass_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0))

i<-23

for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Perennial grass" & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -156,6 +145,13 @@ grass_elect_results <- rbind(grass_elect_results, elect)

vioplot(grass_elect_results$Inter, grass_elect_results$Live, grass_elect_results$Dead)

grass_melt <- melt(grass_elect_results)

grass_anova <- lm(value ~ variable, data = grass_melt)
anova(grass_anova)
summary(grass_anova)

TukeyHSD(aov(grass_anova))


#------------------------------------------------------------------------------------------------------------
Expand All @@ -164,7 +160,7 @@ forb_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0))
i<-1

for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Perennial forb " & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -189,16 +185,21 @@ for (i in 1:length(plots_to_use)){

vioplot(forb_elect_results$Inter, forb_elect_results$Live, forb_elect_results$Dead)

forb_melt <- melt(forb_elect_results)

forb_anova <- lm(value ~ variable, data = forb_melt)
anova(forb_anova)
summary(forb_anova)

TukeyHSD(aov(forb_anova))

#----------------------------------------------------------------------------------------------------------

shrub_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0),
Log = numeric(0))
i<-11
Inter = numeric(0))

for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Shrub " & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -217,25 +218,31 @@ for (i in 1:length(plots_to_use)){
(cov[cov$Group.1 == "Live",2] + prev[which(names(prev) == "Live")]),

Inter = (cov[cov$Group.1 == "Inter",2] - prev[which(names(prev) == "Inter")]) /
(cov[cov$Group.1 == "Inter",2] + prev[which(names(prev) == "Inter")]),
Log = (cov[cov$Group.1 == "Inter",2] - prev[which(names(prev) == "Inter")]) /
(cov[cov$Group.1 == "Inter",2] + prev[which(names(prev) == "Inter")]))

shrub_elect_results <- rbind(shrub_elect_results, elect)
}

shrub_elect_results <- shrub_elect_results[complete.cases(shrub_elect_results), ]

vioplot(shrub_elect_results$Inter, shrub_elect_results$Live, shrub_elect_results$Dead)

#-----------------------------------------------------------------------------------------------------
shrub_melt <- melt(shrub_elect_results)

shrub_anova <- lm(value ~ variable, data = shrub_melt)
anova(shrub_anova)
summary(shrub_anova)

TukeyHSD(aov(forb_anova))

#----------------------------------------------------------------------------------------------------------

cheat_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0))
i<-11

i <- 1
for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Cheatgrass" & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -259,9 +266,20 @@ for (i in 1:length(plots_to_use)){
cheat_elect_results <- rbind(cheat_elect_results, elect)
}

cheat_elect_results <- cheat_elect_results[complete.cases(cheat_elect_results), ]

vioplot(cheat_elect_results$Inter, cheat_elect_results$Live, cheat_elect_results$Dead)

cheat_melt <- melt(cheat_elect_results)

cheat_anova <- lm(value ~ variable, data = cheat_melt)
anova(cheat_anova)
summary(cheat_anova)

TukeyHSD(aov(cheat_anova))



#-----------------------------------------------------------------------------------------------
# For whole study area
#-----------------------------------------------------------------------------------------------
Expand Down
Binary file modified Raw data/Understory_update_110418.xlsx
Binary file not shown.
20 changes: 20 additions & 0 deletions Raw data/microsite.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2024,3 +2024,23 @@ TOI1577,10/2/2015,PW,w,4,PO,25,,,added 11/4/18,
TOI1577,10/2/2015,PW,w,7,PO,14,,,added 11/4/18,
TOI1577,10/2/2015,PW,w,14,PI,15,,,added 11/4/18,
TOI1577,10/2/2015,PW,w,15,I,,,,added 11/4/18,
WHIS64240,7/8/2015,SF,n,3,PI,1,,,added 11/5/18,
WHIS64240,7/8/2015,SF,n,8,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,n,9,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,n,12,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,n,16,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,e,4,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,e,9,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,e,11,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,e,8,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,e,14,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,s,1,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,s,5,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,s,9,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,s,10,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,s,12,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,w,1,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,w,2,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,w,3,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,w,4,I,,,,added 11/5/18,
WHIS64240,7/8/2015,SF,w,10,I,,,,added 11/5/18,
66 changes: 42 additions & 24 deletions understory_electivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ for(i in 1:n_quads_occ){

# import and recode microsite data
ms <- read.csv("./raw data/microsite.csv")
ms$ms <- ifelse(ms$Microsite %in% c("PI", "JI", "CI"), "Live Inner",
ifelse(ms$Microsite %in% c("PO", "JO", "CO"), "Live Outer",
ms$ms <- ifelse(ms$Microsite %in% c("PI", "JI", "CI", "PO", "JO", "CO"), "Live",
# ifelse(ms$Microsite %in% c("PO", "JO", "CO"), "Live Outer",
ifelse(ms$Microsite %in% c("PI(S)", "PO(S)", "JI(S)", "JO(S)", "CI(S)", "CO(S)"), "Dead",
ifelse(ms$Microsite =="LOG", "Log",
ifelse(ms$Microsite == "I", "Inter", NA)))))
ifelse(ms$Microsite == "I", "Inter", NA))))#)
ms[ms$Transect == "e", "Transect"] <- "E"
ms[ms$Transect == "s", "Transect"] <- "S"
ms[ms$Transect == "w", "Transect"] <- "W"
Expand All @@ -98,18 +98,6 @@ ms[ms$Plot == "NPElectricEel120", "Plot"] <- "NPELECTRICEEL120"

ms$unique_quad <- paste0(ms$Plot, ms$Transect, ms$Meter)

unique(ms$Plot)[!(unique(ms$Plot) %in% unique(daub$Plot))]
unique(daub$Plot)[!(unique(daub$Plot) %in% unique(ms$Plot))] #WHIS64240

#how many quadrats are messed up?
table(ms[!(ms$unique_quad %in% unique(daub$unique_quad)), "Plot"])[table(ms[!(ms$unique_quad %in% unique(daub$unique_quad)), "Plot"]) > 0]
#SPR1575 (7 quads), TOI1577360
table(daub[!(daub$unique_quad %in% unique(ms$unique_quad)), "Plot"])/11 #same as above, plus WHIS64240

#which quadrats are messed up?
unique(ms[!(ms$unique_quad %in% unique(daub$unique_quad)), "unique_quad"])
unique(daub[!(daub$unique_quad %in% unique(ms$unique_quad)), "unique_quad"])

#get total cover for each plot
total_cover <- aggregate(daub$Midpoint.value, by = list(daub$Plot, daub$Cover.type), FUN = sum)

Expand All @@ -126,13 +114,14 @@ for(i in 1:length(unique(ms$Plot))){

plots_to_use <- unique(ms$Plot)[plots_to_use_dead & plots_to_use_live]

#-----------------------------------------------------------------------------------------------

grass_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0))

i<-23

for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Perennial grass" & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -156,6 +145,13 @@ grass_elect_results <- rbind(grass_elect_results, elect)

vioplot(grass_elect_results$Inter, grass_elect_results$Live, grass_elect_results$Dead)

grass_melt <- melt(grass_elect_results)

grass_anova <- lm(value ~ variable, data = grass_melt)
anova(grass_anova)
summary(grass_anova)

TukeyHSD(aov(grass_anova))


#------------------------------------------------------------------------------------------------------------
Expand All @@ -164,7 +160,7 @@ forb_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0))
i<-1

for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Perennial forb " & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -189,16 +185,21 @@ for (i in 1:length(plots_to_use)){

vioplot(forb_elect_results$Inter, forb_elect_results$Live, forb_elect_results$Dead)

forb_melt <- melt(forb_elect_results)

forb_anova <- lm(value ~ variable, data = forb_melt)
anova(forb_anova)
summary(forb_anova)

TukeyHSD(aov(forb_anova))

#----------------------------------------------------------------------------------------------------------

shrub_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0),
Log = numeric(0))
i<-11
Inter = numeric(0))

for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Shrub " & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -217,25 +218,31 @@ for (i in 1:length(plots_to_use)){
(cov[cov$Group.1 == "Live",2] + prev[which(names(prev) == "Live")]),

Inter = (cov[cov$Group.1 == "Inter",2] - prev[which(names(prev) == "Inter")]) /
(cov[cov$Group.1 == "Inter",2] + prev[which(names(prev) == "Inter")]),
Log = (cov[cov$Group.1 == "Inter",2] - prev[which(names(prev) == "Inter")]) /
(cov[cov$Group.1 == "Inter",2] + prev[which(names(prev) == "Inter")]))

shrub_elect_results <- rbind(shrub_elect_results, elect)
}

shrub_elect_results <- shrub_elect_results[complete.cases(shrub_elect_results), ]

vioplot(shrub_elect_results$Inter, shrub_elect_results$Live, shrub_elect_results$Dead)

#-----------------------------------------------------------------------------------------------------
shrub_melt <- melt(shrub_elect_results)

shrub_anova <- lm(value ~ variable, data = shrub_melt)
anova(shrub_anova)
summary(shrub_anova)

TukeyHSD(aov(forb_anova))

#----------------------------------------------------------------------------------------------------------

cheat_elect_results <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0))
i<-11

i <- 1
for (i in 1:length(plots_to_use)){

test_grass_cov <- daub[daub$Cover.type == "Cheatgrass" & daub$Plot == as.character(plots_to_use[i]), ]
Expand All @@ -259,9 +266,20 @@ for (i in 1:length(plots_to_use)){
cheat_elect_results <- rbind(cheat_elect_results, elect)
}

cheat_elect_results <- cheat_elect_results[complete.cases(cheat_elect_results), ]

vioplot(cheat_elect_results$Inter, cheat_elect_results$Live, cheat_elect_results$Dead)

cheat_melt <- melt(cheat_elect_results)

cheat_anova <- lm(value ~ variable, data = cheat_melt)
anova(cheat_anova)
summary(cheat_anova)

TukeyHSD(aov(cheat_anova))



#-----------------------------------------------------------------------------------------------
# For whole study area
#-----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 0746d95

Please sign in to comment.