This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
understory_electivity.R
477 lines (377 loc) · 20 KB
/
understory_electivity.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
## Understory electivity
library(plyr)
library(vioplot)
library(reshape2)
library(multcompView)
set.seed(16091315)
daub <- read.csv("./Raw data/daub_cover.csv", stringsAsFactors = FALSE)
#some data proofing
daub <- daub[(daub$Transect %in% c("N", "E", "S", "W")), ]
daub$Plot <- as.character(daub$Plot)
daub[daub$Plot == "NPElectricEel", "Plot"] <- "NPELECTRICEEL"
daub[daub$Plot == "NPElectricEel120", "Plot"] <- "NPELECTRICEEL120"
daub[daub$Plot == "NPElectricEel240", "Plot"] <- "NPELECTRICEEL240"
daub[daub$Plot == "NPElectricEel360", "Plot"] <- "NPELECTRICEEL360"
daub$Midpoint.value <- as.numeric(as.character((daub$Midpoint.value)))
daub$unique_quad <- paste0(daub$Plot, daub$Transect, daub$Meter)
daub[daub$Cover.type == "Perennial forb ", "Cover.type"] <- "Perennial forb"
daub[daub$Cover.type == "Shrub ", "Cover.type"] <- "Shrub"
species<- read.csv("./raw data/spp_cover2.csv")
species <- species[(species$Transect %in% c("N", "E", "S", "W")), ]
species$unique_quad <- paste0(species$Plot, species$Transect, species$Meter)
count(species, vars = c("Plot", "Transect"))
#little test to look at species relationships with CWD
species_aggregate <- aggregate(species[c("Cover")], by = list(species$Plot, species$Species), FUN = mean)
names(species_aggregate)[c(1,2)] <- c("Plot", "Species")
species_aggregate <- join(species_aggregate, plot_data[c("Plot", "cwd_normal_cum")], by = c("Plot"))
plot(log(Cover) ~ cwd_normal_cum, data = species_aggregate[species_aggregate$Species == "ARTTRIV", ],
xlim = c(200, 450))
#-----------------------------------------------------------------------
# Calculate mean cover, cover by quadrat, cover by plot
#-------------------------------------------------------------------
# Mean overall cover
length(unique(daub$unique_quad))
spp_abund <- aggregate(species$Cover / 2040, by = list(species$Species), FUN = sum)
spp_abund <- spp_abund[order(spp_abund[, 1], decreasing = FALSE), ]
#percent of quadrats occupied
quadrat_abund <- as.data.frame(table(species[species$Cover != 0, ]$Species))
quadrat_abund <- quadrat_abund[order(quadrat_abund[, 1], decreasing = FALSE), ]
quadrat_abund[, 2] <- quadrat_abund[, 2] * 100 / 2040
count <- table(species$Species, species$Plot)
is.not.zero <- function(x){
if((x) == 0){return(0)}
else{return(1)}
}
presence <- apply(count, c(1,2), FUN = is.not.zero)
plot_presence <- as.data.frame(rowSums(presence))/102*100
spp_abund <- cbind(spp_abund, quadrat_abund[-1, 2], plot_presence[-1, 1])
write.csv(spp_abund, "./outputs/species_summary.csv")
## generate cover data for different subsets
n_quads_occ <- length(unique(species$unique_quad)) #number of quadrat-by-group records
spp_cov <- data.frame(unique_quad = unique(species$unique_quad),
poasec = numeric(n_quads_occ),
othergrass = numeric(n_quads_occ),
phlhoo = numeric(n_quads_occ),
otherforb = numeric(n_quads_occ))
for(i in 1:n_quads_occ){
spp_cov$poasec[i] <- ifelse(species[species$unique_quad == spp_cov$unique_quad[i], ]$Species == "POASEC",
species[species$unique_quad == spp_cov$unique_quad[i] & species$Species == "POASEC", ]$Cover, 0)
spp_cov$othergrass[i] <- ifelse(species[species$unique_quad == spp_cov$unique_quad[i], ]$Species %in% c("PSESPI", "LEYCIN", "ELYELY", "STITHU"),
sum(species[species$unique_quad == spp_cov$unique_quad[i]
& species$Species %in% c("PSESPI", "LEYCIN", "ELYELY", "STITHU"), ]$Cover), 0)
spp_cov$phlhoo[i] <- ifelse(species[species$unique_quad == spp_cov$unique_quad[i], ]$Species == "PHLHOO",
species[species$unique_quad == spp_cov$unique_quad[i] & species$Species == "PHLHOO", ]$Cover, 0)
spp_cov$otherforb[i] <- ifelse(species[species$unique_quad == spp_cov$unique_quad[i], ]$Species %in% c("CREACA", "CREACU", "STEACA", "ERICAE", "LEPPUN", "ERIUMB", "AREACU","LESKIN","GALAPA","ASTPUR","BALSAG","CRYFLA","ERIMIC","MINKIN","ASTOOP","OPUPOL","ARAHOL","ANTDIM","BOEHOL"),
sum(species[species$unique_quad == spp_cov$unique_quad[i]
& species$Species %in% c("CREACA", "CREACU", "STEACA", "ERICAE", "LEPPUN", "ERIUMB", "AREACU","LESKIN","GALAPA","ASTPUR","BALSAG","CRYFLA","ERIMIC","MINKIN","ASTOOP","OPUPOL","ARAHOL","ANTDIM","BOEHOL"), ]$Cover), 0)
}
#----------------------------------------------------------------------------
# import and recode microsite data
ms <- read.csv("./raw data/microsite.csv")
ms$Microsite <- toupper(ms$Microsite)
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)", "LOG"), "Dead",
# ifelse(ms$Microsite =="LOG", "Log",
ifelse(ms$Microsite == "I", "Inter", NA)))#))
ms[ms$Transect == "e", "Transect"] <- "E"
ms[ms$Transect == "s", "Transect"] <- "S"
ms[ms$Transect == "w", "Transect"] <- "W"
ms[ms$Transect == "n", "Transect"] <- "N"
ms$Plot <- as.character(ms$Plot)
ms <- ms[(ms$Transect %in% c("N", "S", "E", "W")), ]
ms[ms$Plot == "NPElectricEel120", "Plot"] <- "NPELECTRICEEL120"
ms$unique_quad <- paste0(ms$Plot, ms$Transect, ms$Meter)
#get total cover for each plot
total_cover <- aggregate(daub$Midpoint.value, by = list(daub$Plot, daub$Cover.type), FUN = sum)
## select which plots have enough microsites of each type
# this is a real friggin mess but it pulls out the plots which have
# at least n_plots dead and at least n_plots live ms
plots_to_use_dead <- NA
plots_to_use_live <- NA
n_plots <- 1
for(i in 1:length(unique(ms$Plot))){
table <- table(ms[ms$Plot == unique(ms$Plot)[i], ]$ms)
if("Dead" %in% names(table)){
plots_to_use_dead[i] <- table["Dead"]
} else{
plots_to_use_dead[i] <- 0
}
if("Live" %in% names(table)){
plots_to_use_live[i] <- table["Live"]
} else{
plots_to_use_live[i] <- 0
}
}
plots_to_use_dead <- (plots_to_use_dead >= n_plots)
plots_to_use_live <- (plots_to_use_live >= n_plots)
plots_to_use <- unique(ms$Plot)[plots_to_use_dead & plots_to_use_live]
#------------------------------------------------------------------------------
# Calculate test and randomized distributions
#------------------------------------------------------------------------------
#perform analysis for the four FTs
types <- c("Perennial grass", "Cheatgrass", "Perennial forb", "Shrub")
ntypes <- length(types)
#initialize a list of dataframes to catch the electivities at each plot/FT
elect_results <- list()
for(i in 1:ntypes){
elect_results[[i]] <- data.frame(Plot = numeric(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0),
DL = numeric(0),
DI = numeric(0),
LI = numeric(0))
}
names(elect_results) <- types
for(type in types){ # calculate electivity for each functional type
for (i in 1:length(plots_to_use)){
if(type == "All"){
daub_cov <- daub[daub$Plot == as.character(plots_to_use[i]), ]
daub_cov <- daub_cov[daub_cov$Cover.type %in% c("Cheatgrass", "Other Ann Grass",
"Perennial grass", "Annual forb", "Perennial forb", "Shrub"), ]
daub_cov_2 <- aggregate(daub_cov$Midpoint.value, by = list(daub_cov$unique_quad), FUN = sum)
names(daub_cov_2) <- c("unique_quad", "Midpoint.value")
daub_cov <- join(daub_cov_2, ms[, c("unique_quad", "ms")], by = "unique_quad", type = "inner")
}else{
daub_cov <- daub[daub$Cover.type == type & daub$Plot == as.character(plots_to_use[i]), ]
daub_cov <- join(daub_cov, ms[, c("unique_quad", "ms")], by = "unique_quad", type = "inner")
}
daub_cov$prop_cov <- daub_cov$Midpoint.value / sum(daub_cov$Midpoint.value)
cov <- aggregate(daub_cov[, "prop_cov"], by = list(daub_cov$ms), FUN = sum)
prev <- table(daub_cov$ms)/20
#this is a mess because tables are hard to use. There's definitely a better way to do this
elect <- data.frame(Plot = plots_to_use[i],
Dead = (cov[cov$Group.1 == "Dead",2] - prev[which(names(prev) == "Dead")]) /
(cov[cov$Group.1 == "Dead", 2] + prev[which(names(prev) == "Dead")]),
Live = (cov[cov$Group.1 == "Live",2] - prev[which(names(prev) == "Live")]) /
(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 = (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
#------------------------------------------------------------------------------
nit <- 999 #number of monte carlo draws
#initialize a list of dataframes to catch the electivities at each plot/FT
elect_means <- list()
for(i in 1:ntypes){
elect_means[[i]] <- data.frame(Iter = numeric(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0),
DL = numeric(0),
DI = numeric(0),
LI = numeric(0))
}
names(elect_means) <- types
system.time(#takes about a half hour
for(type in types){
plot_to_use_type <- subset(elect_results[[type]], !is.na(Dead))$Plot
for(j in 1:nit){
elect_rand <- data.frame(Plot = character(0),
Dead = numeric(0),
Live = numeric(0),
Inter = numeric(0),
DL = numeric(0),
DI = numeric(0),
DL = numeric(0))
for (plot_use in plot_to_use_type){
if(type == "All"){
daub_cov <- daub[daub$Plot == as.character(plot_use), ]
daub_cov <- daub_cov[daub_cov$Cover.type %in% c("Cheatgrass", "Other Ann Grass",
"Perennial grass", "Annual forb", "Perennial forb", "Shrub"), ]
daub_cov_2 <- aggregate(daub_cov$Midpoint.value, by = list(daub_cov$unique_quad), FUN = sum)
names(daub_cov_2) <- c("unique_quad", "Midpoint.value")
daub_cov <- join(daub_cov_2, ms[, c("unique_quad", "ms")], by = "unique_quad", type = "inner")
}else{
daub_cov <- daub[daub$Cover.type == type & daub$Plot == as.character(plot_use), ]
daub_cov <- join(daub_cov, ms[, c("unique_quad", "ms")], by = "unique_quad", type = "inner")
}
daub_cov$prop_cov <- daub_cov$Midpoint.value / sum(daub_cov$Midpoint.value)
daub_cov$prop_cov_ran <- sample(daub_cov$prop_cov, size = 20, replace = FALSE)
cov <- aggregate(daub_cov[, "prop_cov_ran"], by = list(daub_cov$ms), FUN = sum)
prev <- table(daub_cov$ms)/20
elect <- data.frame(Plot = plot_use,
Dead = (cov[cov$Group.1 == "Dead",2] - prev[which(names(prev) == "Dead")]) /
(cov[cov$Group.1 == "Dead", 2] + prev[which(names(prev) == "Dead")]),
Live = (cov[cov$Group.1 == "Live",2] - prev[which(names(prev) == "Live")]) /
(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 = (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)
}
means <- apply(elect_rand[, c(2:7)], 2, FUN = function(x){mean(x, na.rm = TRUE)})
elect_means[[type]][j, 1] <- j
elect_means[[type]][j, 2:7] <- means
}
}
)
results_boots <- list()
for(i in 1:ntypes){
results_boots[[i]] <- data.frame(Dead = numeric(2),
Live = numeric(2),
Inter = numeric(2),
DL = numeric(2),
DI = numeric(2),
LI = numeric(2))
rownames(results_boots[[i]]) <- c("Empirical", "N_boots_greater")
}
names(results_boots) <- types
#calculate p-values from distribution of bootstrapped mean electivities
for(i in 1:ntypes){
emp_mean <- apply(elect_results[[i]][, 2:7], 2, FUN = function(x){mean(x, na.rm = TRUE)})
pvals <- c(sum(elect_means[[i]][2] > emp_mean[1]),
sum(elect_means[[i]][3] > emp_mean[2]),
sum(elect_means[[i]][4] > emp_mean[3]),
sum(elect_means[[i]][5] > emp_mean[4]),
sum(elect_means[[i]][6] > emp_mean[5]),
sum(elect_means[[i]][7] > emp_mean[6]))
#flip around large p-values to make them small p-values for the left tail
pvals <- ifelse(pvals > (nit + 1)/2, (nit + 1 - pvals)/(nit + 1), pvals/(nit + 1))
results_boots[[i]][1, ] <- emp_mean
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="./outputs/electivity.png",
type="cairo",
units="in",
width = 4,
height=4,
pointsize=10,
res=600)
par(mfrow = c(2,2),
mar = c(2,1,1,2),
oma = c(2,3,1,0))
for(i in 1:ntypes){
melt_elect <- melt(elect_results[[i]][, 2:4])
plot(NA,
ylim = c(-1,1),
xlim = c(.7, 3.3),
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.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"],
# y1 = melt_elect[melt_elect$variable == "Live", "value"])
#
# segments(x0 = 2, x1 = 3, y0 = melt_elect[melt_elect$variable == "Live", "value"],
# y1 = melt_elect[melt_elect$variable == "Inter", "value"])
if(i %in% c(1,2)){
axis(1, at = c(1,2,3), labels = FALSE)
}
if(i %in% c(3,4)){
axis(1, at = c(1,2,3), labels = c("Dead", "Live", "Inter"))
}
# 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 = "Ivlev's E", outer = TRUE, side = 2, line = 1.5)
}
dev.off()
#
# #-----------------------------------------------------------------------------------------------
# # For whole study area
# #-----------------------------------------------------------------------------------------------
# all_merged <- join(daub, ms, by = "unique_quad", type = "inner")
#
# daub$unique_quad
# ms$unique_quad
#
#
# all_plots_prev <- table(all_merged$ms)
# all_plots_prev <- all_plots_prev / sum(all_plots_prev)
#
# all_plots_cover <- aggregate(all_merged$Midpoint.value, by = list(all_merged$Cover.type, all_merged$ms), FUN = sum)
# all_plots_cover <- all_plots_cover[all_plots_cover$Group.1 %in% c("Perennial grass", "Perennial forb ", "Shrub ", "Cheatgrass"), ]
#
# for (i in 1:4){ # standardized cover so it adds to 1 for each functional type
# types <- c("Cheatgrass", "Perennial forb ", "Perennial grass", "Shrub ")
# all_plots_cover[all_plots_cover$Group.1 == types[i], "x"] <- all_plots_cover[all_plots_cover$Group.1 == types[i], "x"] /
# sum(all_plots_cover[all_plots_cover$Group.1 == types[i], "x"])
# }
#
#
#
# all_plots_cover <- dcast(all_plots_cover, Group.1 ~ Group.2) #reshapes the table
#
# all_elect <- data.frame(type = c("Cheatgrass", "Perennial forb", "Perennial grass", "Shrub"),
# Dead = numeric(4),
# Inter = numeric(4),
# LiveInner = numeric(4),
# LiveOuter = numeric(4),
# Log = numeric(4))
#
# for (i in 2:6){ #calculate electivity
# for (j in 1:4){
# all_elect[j, i] <- (all_plots_cover[j,i] - all_plots_prev[i - 1]) / (all_plots_cover[j,i] + all_plots_prev[i - 1])
# }
# }
#
#
# #--------------------------------------------------------------------
#
# spp_merged <- join(spp_cov, ms, by = "unique_quad", type = "inner")
# head(spp_merged)
#
#
# spp_plots_prev <- table(spp_merged$ms)
# spp_plots_prev <- spp_plots_prev / sum(spp_plots_prev)
#
# spp_merged$poasec <- spp_merged$poasec / sum(spp_merged$poasec)
# spp_merged$othergrass <- spp_merged$othergrass / sum(spp_merged$othergrass)
# spp_merged$phlhoo <- spp_merged$phlhoo / sum(spp_merged$phlhoo)
# spp_merged$otherforb <- spp_merged$otherforb / sum(spp_merged$otherforb)
#
# spp_ag <- aggregate(spp_merged[, c("poasec", "othergrass", "phlhoo", "otherforb")], by = list(spp_merged$ms), FUN = sum)
#
#
# spp_elect <- data.frame(type = c("POASEC", "Other Perr Grass", "PHLHOO", "Other Forb"),
# Dead = numeric(4),
# Inter = numeric(4),
# LiveInner = numeric(4),
# LiveOuter = numeric(4),
# Log = numeric(4))
#
# for (i in 1:5){ #calculate electivity
# for (j in 1:4){
# spp_elect[j, i+1] <- (unname(spp_ag[i,j + 1]) - unname(all_plots_prev[i])) / (unname(spp_ag[i,j + 1]) + unname(all_plots_prev[i]))
# }
# }
#