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

Commit

Permalink
Updated electivity figures
Browse files Browse the repository at this point in the history
Added RII analysis and revised electivity figure and results table
  • Loading branch information
flakesw committed Apr 16, 2019
1 parent fee0058 commit 309ae6d
Show file tree
Hide file tree
Showing 52 changed files with 972 additions and 2,374 deletions.
Binary file modified .RData
Binary file not shown.
964 changes: 482 additions & 482 deletions .Rhistory

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .Rproj.user/EAEB7255/console06/INDEX001
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"","caption":"Terminal 1","channel_id":"7526","channel_mode":1,"child_procs":false,"cols":93,"cwd":"","exit_code":15,"handle":"98DD95A6","interaction_mode":2,"max_output_lines":1000,"restarted":false,"rows":48,"shell_type":3,"show_on_output":false,"terminal_sequence":1,"title":"","track_env":false,"zombie":false}]
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n\n\n","caption":"Terminal 1","channel_id":"7526","channel_mode":1,"child_procs":false,"cols":93,"cwd":"","exit_code":15,"handle":"98DD95A6","interaction_mode":2,"max_output_lines":1000,"restarted":false,"rows":48,"shell_type":3,"show_on_output":false,"terminal_sequence":1,"title":"","track_env":false,"zombie":false}]
2 changes: 1 addition & 1 deletion .Rproj.user/EAEB7255/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab" : -1
"activeTab" : 3
}
14 changes: 7 additions & 7 deletions .Rproj.user/EAEB7255/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left" : {
"panelheight" : 779,
"splitterpos" : 326,
"topwindowstate" : "HIDE",
"windowheight" : 817
"panelheight" : 903,
"splitterpos" : 377,
"topwindowstate" : "NORMAL",
"windowheight" : 941
},
"right" : {
"panelheight" : 779,
"splitterpos" : 488,
"panelheight" : 903,
"splitterpos" : 566,
"topwindowstate" : "NORMAL",
"windowheight" : 817
"windowheight" : 941
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/EAEB7255/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"TabSet1" : 0,
"TabSet2" : 1,
"TabSet2" : 3,
"TabZoom" : {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "1518548566",
"hash" : "1342804317",
"id" : "9E5C163F",
"lastKnownWriteTime" : 1551912261,
"last_content_update" : 1551912261877,
"lastKnownWriteTime" : 1555353610,
"last_content_update" : 1555353610314,
"path" : "~/Research/MS Thesis/Understory/plot_level_understory.R",
"project_path" : "plot_level_understory.R",
"properties" : {
"cursorPosition" : "298,47",
"scrollLine" : "286"
"cursorPosition" : "69,14",
"scrollLine" : "0"
},
"relative_order" : 1,
"source_on_save" : false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ greenwood_under <- read.csv("./raw data/Greenwood_Understory_Variables_SF_edits.
hist(asin(sqrt(plot_data$All/100)))
hist(logit(plot_data$All/100 + min(plot_data[plot_data$All != 0, "All"])))
hist(log(plot_data$All/100))
plot((plot_data$All/100) ~ plot_data$Tree_cover)
plot(asin(sqrt(plot_data$All/100)) ~ plot_data$Tree_cover)
plot(asin(sqrt(plot_data$All/100)) ~ plot_data$Delta_pdc)
plot(asin(sqrt(plot_data$All/100)) ~ plot_data$cwd_normal_cum)

hist(asin(sqrt(plot_data$Cheatgrass/100)))
hist(logit(plot_data$Cheatgrass/100 + min(plot_data[plot_data$Cheatgrass != 0, "Cheatgrass"])))
Expand Down Expand Up @@ -54,11 +58,11 @@ plot(plot_data$Cheatgrass ~ plot_data$cwd_normal_cum)
all_plot <- lmer(asin(sqrt(All/100)) ~ scale(Tree_cover) + scale(Delta_pdc)*scale(cwd_normal_cum) +
scale(AWC) + (1|Cluster), data = plot_data)

all_plot <- lmer(logit(All/100) ~ scale(Tree_cover) + scale(Delta_pdc)*scale(cwd_normal_cum) +
scale(AWC) + (1|Cluster), data = plot_data)

summary(lm(asin(sqrt(All/100)) ~ scale(Tree_cover) + scale(Delta_pdc)*scale(cwd_normal_cum) +
scale(AWC), data = plot_data))
# all_plot <- lmer(logit(All/100) ~ scale(Tree_cover) + scale(Delta_pdc)*scale(cwd_normal_cum) +
# scale(AWC) + (1|Cluster), data = plot_data)
#
# summary(lm(asin(sqrt(All/100)) ~ scale(Tree_cover) + scale(Delta_pdc)*scale(cwd_normal_cum) +
# scale(AWC), data = plot_data))

summary(all_plot, ddf = "Kenward-Roger")
r.squaredGLMM(all_plot)
Expand Down Expand Up @@ -136,7 +140,7 @@ coefplot2(cheatgrass_plot, add = TRUE, spacing = 10)


#-----------------------------------------------
# Comparison of greenwood and 2015
# Comparison between 2005 and 2015 samples
#-----------------------------------------------
compare <- join(plot_data, greenwood_under, by = "Plot", type = "inner")

Expand All @@ -154,8 +158,9 @@ cor.test(compare$Cheatgrass - compare$Cheatgrass.Cover, compare$cwd_normal_cum,
alternative = "two.sided", exact = FALSE)

#linear model of log change ~ delta pdc and cwd
compare$log_cg_change <- log(I(compare$Cheatgrass/100 - compare$Cheatgrass.Cover/100 - min(compare$Cheatgrass/100 - compare$Cheatgrass.Cover/100) + .01))
cg_change_lm <- lm(log_cg_change ~ Delta_pdc*cwd_normal_cum, data= compare)
# compare <- compare[-10, ] #outlier to remove?

cg_change_lm <- lm(I((Cheatgrass - Cheatgrass.Cover)/100) ~ Delta_pdc*cwd_normal_cum, data= compare)

summary(cg_change_lm)
plot(cg_change_lm)
Expand All @@ -168,7 +173,6 @@ mean(compare$log_cg_change[-c(5,10)])
(compare$log_cg_change[c(5)] - 1.72) / .18
(compare$log_cg_change[c(10)] - 1.72) / .18


summary(cg_change_lm)
plot(cg_change_lm)
plot(allEffects(cg_change_lm, partial.residuals = TRUE))
Expand All @@ -183,8 +187,9 @@ mean(compare$Pgrass-compare$Perrenial.Grass.Cover)
t.test(compare$Pgrass, compare$Perrenial.Grass.Cover, paired = TRUE, alternative="less")
wilcox.test(compare$Pgrass, compare$Perrenial.Grass.Cover, paired = TRUE, alternative="less")

pg_change_lm <- lm(Pgrass - Perrenial.Grass.Cover ~ Delta_pdc*cwd_normal_cum, data= compare)
pg_change_lm <- lm(Pgrass - Perrenial.Grass.Cover ~ cwd_normal_cum, data= compare)
summary(pg_change_lm)
plot(allEffects(pg_change_lm))

## Perr forb
plot(I(compare$Aforb + compare$Pforb) ~ compare$Forb.Cover)
Expand Down
23 changes: 23 additions & 0 deletions .Rproj.user/EAEB7255/sources/per/t/BA4339
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"collab_server" : "",
"contents" : "",
"created" : 1553632933662.000,
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "125392788",
"id" : "BA4339",
"lastKnownWriteTime" : 1555449165,
"last_content_update" : 1555449165855,
"path" : "~/Research/MS Thesis/Understory/understory_electivity.R",
"project_path" : "understory_electivity.R",
"properties" : {
"cursorPosition" : "397,2",
"scrollLine" : "384",
"tempName" : "Untitled1"
},
"relative_order" : 5,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library(multcompView)

set.seed(16091315)

daub <- read.csv("./raw data/daub_cover.csv", stringsAsFactors = FALSE)
daub <- read.csv("./Raw data/daub_cover.csv", stringsAsFactors = FALSE)

#some data proofing
daub <- daub[(daub$Transect %in% c("N", "E", "S", "W")), ]
Expand Down Expand Up @@ -158,7 +158,7 @@ for(i in 1:ntypes){
names(elect_results) <- types


for(type in types){
for(type in types){ # calculate electivity for each functional type

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

Expand Down Expand Up @@ -189,16 +189,18 @@ for(type in types){
(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")]))
elect$DL = elect$Dead - elect$Live
elect$DI = elect$Dead - elect$Inter
elect$LI = elect$Live - elect$Inter
elect$DL = (cov[cov$Group.1 == "Dead",2] - cov[cov$Group.1 == "Live",2]) / (cov[cov$Group.1 == "Dead",2] + cov[cov$Group.1 == "Live",2])
elect$DI = (cov[cov$Group.1 == "Dead",2] - cov[cov$Group.1 == "Inter",2]) / (cov[cov$Group.1 == "Dead",2] + cov[cov$Group.1 == "Inter",2])
elect$LI = (cov[cov$Group.1 == "Live",2] - cov[cov$Group.1 == "Inter",2]) / (cov[cov$Group.1 == "Live",2] + cov[cov$Group.1 == "Inter",2])

elect_results[[type]] <- rbind(elect_results[[type]], elect)
}
}

saveRDS(elect_results, paste0("./outputs/results_elect_", n_plots, "dead.rds"))
# elect_results <- readRDS("./outputs/results_elect_1dead.rds")


#------------------------------------------------------------------------------
#Calculate monte carlo means
#------------------------------------------------------------------------------
Expand Down Expand Up @@ -260,9 +262,9 @@ for(type in types){
(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")]))
elect$DL = elect$Dead - elect$Live
elect$DI = elect$Dead - elect$Inter
elect$LI = elect$Live - elect$Inter
elect$DL = (cov[cov$Group.1 == "Dead",2] - cov[cov$Group.1 == "Live",2]) / (cov[cov$Group.1 == "Dead",2] + cov[cov$Group.1 == "Live",2])
elect$DI = (cov[cov$Group.1 == "Dead",2] - cov[cov$Group.1 == "Inter",2]) / (cov[cov$Group.1 == "Dead",2] + cov[cov$Group.1 == "Inter",2])
elect$LI = (cov[cov$Group.1 == "Live",2] - cov[cov$Group.1 == "Inter",2]) / (cov[cov$Group.1 == "Live",2] + cov[cov$Group.1 == "Inter",2])

elect_rand <- rbind(elect_rand, elect)
}
Expand Down Expand Up @@ -311,17 +313,35 @@ results_boots[[i]][2, ] <- pvals
saveRDS(results_boots, paste0("./outputs/results_boots_", n_plots, "dead.rds"))

# results_boots <- readRDS("./outputs/results_boots_1dead.rds")


#-----------------------------------------------------------------------------------------------
# Summary table
#-----------------------------------------------------------------------------------------------
summary <- as.data.frame(matrix(nrow = 12, ncol = 8))
for(i in 1:4){
for(j in 1:6){
summary[3*i - 2, j+2] <- results_boots[[i]][[j]][[1]]
summary[3*i - 1, j+2] <- results_boots[[i]][[j]][[1]] - mean(elect_means[[i]][[j + 1]])
summary[3*i, j+2] <- results_boots[[i]][[j]][[2]]
}
}

summary[, 2] <- rep(c("Empirical", "Difference", "p-val"), times = 4)
summary[, 1] <- rep(c("Perennial grass", "Cheatgrass", "Perennial forb", "Shrub"), each = 3)
names(summary) <- c("FT", "var", "Dead", "Live", "Inter", "D-L", "D-I", "L-I")
write.csv(summary, "./outputs/electivity summary table.csv")
#-----------------------------------------------------------------------------------------------
# Plot of electivity for each FT
#-----------------------------------------------------------------------------------------------

png(filename="electivity.png",
png(filename="./outputs/electivity.png",
type="cairo",
units="in",
width = 4,
height=4,
pointsize=10,
res=160)
res=600)

par(mfrow = c(2,2),
mar = c(2,1,1,2),
Expand All @@ -330,18 +350,23 @@ par(mfrow = c(2,2),
for(i in 1:ntypes){

melt_elect <- melt(elect_results[[i]][, 2:4])
plot(melt_elect$value ~ I(as.numeric(melt_elect$variable)+ runif(nrow(melt_elect), -.1, .1 )),
plot(NA,
ylim = c(-1,1),
xlim = c(.7, 3.3),
pch = 21,
bg = "grey",
xaxt = "n")
pvals <- results_boots[[i]][2, ]
abline(h = 0)

vioplot(elect_means[[i]][[2]], add = TRUE, col = addTrans("blue", 30), drawRect = FALSE)
vioplot(elect_means[[i]][[3]], at = 2, add = TRUE, col = addTrans("blue", 30), drawRect = FALSE)
vioplot(elect_means[[i]][[4]], at = 3, add = TRUE, col = addTrans("blue", 30), drawRect = FALSE)

points(melt_elect$value ~ I(as.numeric(melt_elect$variable)+ runif(nrow(melt_elect), -.1, .1 )),
pch = 21,
bg = "grey")
means <- aggregate(melt_elect$value, by = list(melt_elect$variable), FUN = function(x){mean(x, na.rm = TRUE)})

segments(x0 = c(0.9, 1.9, 2.9), y0 = means$x, x1 = c(1.1, 2.1, 3.1), lwd = 3)
segments(x0 = c(0.85, 1.85, 2.85), y0 = means$x, x1 = c(1.15, 2.15, 3.15), lwd = 3)


# segments(x0 = 1, x1 = 2, y0 = melt_elect[melt_elect$variable == "Dead", "value"],
Expand All @@ -355,18 +380,21 @@ for(i in 1:ntypes){
}

if(i %in% c(3,4)){
axis(1, at = c(1,2,3), labels = c("Dead", "Live", "Interspace"))
axis(1, at = c(1,2,3), labels = c("Dead", "Live", "Inter"))
}

text(x = c(1,2,3), y = 0.9, labels = pvals[2:4])
# text(x = c(1,2,3), y = 0.9, labels = pvals[4:6])
mtext(text = types[i], outer = FALSE, side = 3, line = 0.3)
mtext(text = paste0("(", letters[i], ")"), outer = FALSE, side = 3, at = 0.5, line = 0.3)
mtext(text = "Electivity", outer = TRUE, side = 2, line = 1.5)
mtext(text = "Ivlev's E", outer = TRUE, side = 2, line = 1.5)



}

dev.off()


#
# #-----------------------------------------------------------------------------------------------
# # For whole study area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "0",
"hash" : "1335816267",
"id" : "F8B392EE",
"lastKnownWriteTime" : 1547472910,
"last_content_update" : 1547472910192,
"lastKnownWriteTime" : 1555347261,
"last_content_update" : 1555347262000,
"path" : "~/Research/MS Thesis/Understory/understory_effects_plots.R",
"project_path" : "understory_effects_plots.R",
"properties" : {
"cursorPosition" : "13,21",
"scrollLine" : "4"
"cursorPosition" : "111,0",
"scrollLine" : "0"
},
"relative_order" : 2,
"source_on_save" : false,
Expand Down
Loading

0 comments on commit 309ae6d

Please sign in to comment.