#clear environment
rm(list = ls())
#Set working directory and CRAN mirror
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = "C:/Users/aliso/OneDrive/Documents/SUNY/THESIS/R/Second Round/Shiny")
options(repos = "https://cloud.r-project.org")
#Data
NestedMatrix <- read.csv("Data/NestedMatrixCSV.csv")
#Omit Site names (not numeric)
original_data <- NestedMatrix[, -1]
#Shapiro-Wilks to test for normality of distribution for all variables
shapiro.test(original_data$Allicin)
##
## Shapiro-Wilk normality test
##
## data: original_data$Allicin
## W = 0.85567, p-value = 0.002261
shapiro.test(original_data$Fresh)
##
## Shapiro-Wilk normality test
##
## data: original_data$Fresh
## W = 0.91851, p-value = 0.04738
shapiro.test(original_data$Dry)
##
## Shapiro-Wilk normality test
##
## data: original_data$Dry
## W = 0.95257, p-value = 0.2863
shapiro.test(original_data$Bulb)
##
## Shapiro-Wilk normality test
##
## data: original_data$Bulb
## W = 0.95496, p-value = 0.3233
shapiro.test(original_data$BulbWidth)
##
## Shapiro-Wilk normality test
##
## data: original_data$BulbWidth
## W = 0.95509, p-value = 0.3254
shapiro.test(original_data$SLA)
##
## Shapiro-Wilk normality test
##
## data: original_data$SLA
## W = 0.94682, p-value = 0.2124
shapiro.test(original_data$N)
##
## Shapiro-Wilk normality test
##
## data: original_data$N
## W = 0.78958, p-value = 0.0001531
shapiro.test(original_data$C)
##
## Shapiro-Wilk normality test
##
## data: original_data$C
## W = 0.68324, p-value = 4.372e-06
shapiro.test(original_data$OM)
##
## Shapiro-Wilk normality test
##
## data: original_data$OM
## W = 0.89172, p-value = 0.01217
shapiro.test(original_data$pH)
##
## Shapiro-Wilk normality test
##
## data: original_data$pH
## W = 0.85499, p-value = 0.002194
shapiro.test(original_data$Mg)
##
## Shapiro-Wilk normality test
##
## data: original_data$Mg
## W = 0.80089, p-value = 0.0002352
shapiro.test(original_data$Ca)
##
## Shapiro-Wilk normality test
##
## data: original_data$Ca
## W = 0.84834, p-value = 0.001638
shapiro.test(original_data$Al)
##
## Shapiro-Wilk normality test
##
## data: original_data$Al
## W = 0.83346, p-value = 0.0008686
shapiro.test(original_data$Fe)
##
## Shapiro-Wilk normality test
##
## data: original_data$Fe
## W = 0.85574, p-value = 0.002268
shapiro.test(original_data$Mn)
##
## Shapiro-Wilk normality test
##
## data: original_data$Mn
## W = 0.83814, p-value = 0.001058
shapiro.test(original_data$P)
##
## Shapiro-Wilk normality test
##
## data: original_data$P
## W = 0.86403, p-value = 0.00329
shapiro.test(original_data$S)
##
## Shapiro-Wilk normality test
##
## data: original_data$S
## W = 0.75602, p-value = 4.567e-05
shapiro.test(original_data$Slope)
##
## Shapiro-Wilk normality test
##
## data: original_data$Slope
## W = 0.80783, p-value = 0.000308
shapiro.test(original_data$Aspect)
##
## Shapiro-Wilk normality test
##
## data: original_data$Aspect
## W = 0.84866, p-value = 0.001661
shapiro.test(original_data$PPFD1)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFD1
## W = 0.85326, p-value = 0.002032
shapiro.test(original_data$PPFD2)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFD2
## W = 0.77704, p-value = 9.64e-05
shapiro.test(original_data$PPFD3)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFD3
## W = 0.73994, p-value = 2.639e-05
shapiro.test(original_data$PPFD4)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFD4
## W = 0.82091, p-value = 0.0005182
shapiro.test(original_data$PPFD5)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFD5
## W = 0.82775, p-value = 0.0006853
shapiro.test(original_data$PPFD6)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFD6
## W = 0.75279, p-value = 4.085e-05
shapiro.test(original_data$PPFDROC)
##
## Shapiro-Wilk normality test
##
## data: original_data$PPFDROC
## W = 0.79205, p-value = 0.000168
shapiro.test(original_data$WeeklyTempROC)
##
## Shapiro-Wilk normality test
##
## data: original_data$WeeklyTempROC
## W = 0.71646, p-value = 1.224e-05
shapiro.test(original_data$TempMax)
##
## Shapiro-Wilk normality test
##
## data: original_data$TempMax
## W = 0.87007, p-value = 0.00434
shapiro.test(original_data$TempMin)
##
## Shapiro-Wilk normality test
##
## data: original_data$TempMin
## W = 0.81974, p-value = 0.0004945
shapiro.test(original_data$TempMean)
##
## Shapiro-Wilk normality test
##
## data: original_data$TempMean
## W = 0.7736, p-value = 8.509e-05
shapiro.test(original_data$TempROC)
##
## Shapiro-Wilk normality test
##
## data: original_data$TempROC
## W = 0.87582, p-value = 0.005673
library(ggplot2)
library(tidyr)
#Gathered data into long format for simultaneous visualization.
gathered_data <- original_data %>%
pivot_longer(
cols = everything(),
names_to = "variable",
values_to = "value")
ggplot(gathered_data, aes(x = variable, y = value, fill = variable)) + geom_violin(trim = FALSE, alpha = 0.7) + labs(title = "Original Distributions of Variables", x = "Variable", y = "Value") + facet_wrap(~variable, scales = "free") + theme_minimal()
#Log transformation and subsequent z-score standardization
original_data_log <- original_data
original_data_log[, sapply(original_data_log, is.numeric)] <- log(original_data_log[, sapply(original_data_log, is.numeric)] + 1)
logzdata <- as.data.frame(scale(original_data_log))
#Plot all transformed/standardized variables
gathered_logzdata <- gather(logzdata, key = "variable", value = "value")
ggplot(gathered_logzdata, aes(x = variable, y = value, fill = variable)) + geom_violin(trim = FALSE, alpha = 0.7) + labs(title = "Transformed Distributions of Variables", x = "Variable", y = "Value") + facet_wrap(~variable, scales = "free") + theme_minimal()
#Create data frame - only z-score standardization
zdata <- as.data.frame(scale(original_data))
library(heatmaply)
library(dplyr)
cor_matrix <- cor(zdata, method = "pearson")
heatmaply(cor_matrix, symm = TRUE, scale_fill_gradient_fun = "viridis", plot_method = "plotly", width = 800, height = 600, main = "Interactive Pearson Correlation Coefficient HeatMap", limits = c(-1, 1))
# Get the absolute values of the correlation matrix
abs_cor_matrix <- abs(cor_matrix)
# Get only the upper triangle of the absolute correlation matrix (excluding the diagonal) to avoid duplication
upper_tri <- upper.tri(abs_cor_matrix, diag = FALSE)
# Get the indices of the highest absolute correlation values
indices <- which(upper_tri, arr.ind = TRUE)
# Data frame to store variable pairs and their correlation coefficients
variable_pairs <- data.frame(var1 = rownames(abs_cor_matrix)[indices[, 1]],
var2 = colnames(abs_cor_matrix)[indices[, 2]],
correlation = abs_cor_matrix[upper_tri])
# Remove duplicate pairs (e.g., var1-var2 and var2-var1)
variable_pairs <- variable_pairs[!duplicated(t(apply(variable_pairs[, 1:2], 1, sort))), ]
# Sort by correlation coefficient in descending order
variable_pairs <- variable_pairs[order(-variable_pairs$correlation), ]
# Print the variable pairs with the highest absolute correlation values
print(variable_pairs)
## var1 var2 correlation
## 105 Al Fe 0.993670396
## 76 pH Ca 0.985890070
## 332 N PPFDROC 0.985629388
## 343 S PPFDROC 0.982663640
## 333 C PPFDROC 0.974902207
## 101 pH Fe 0.974320926
## 88 pH Al 0.972929724
## 144 C S 0.971883720
## 28 N C 0.966496438
## 143 N S 0.966088131
## 136 Mn P 0.965931604
## 35 N OM 0.963033288
## 389 Mg TempMax 0.944750729
## 55 pH Mg 0.934428214
## 104 Ca Fe 0.933963076
## 346 PPFD1 PPFDROC 0.932268309
## 276 PPFD3 PPFD4 0.928408293
## 91 Ca Al 0.928098025
## 77 Mg Ca 0.924520233
## 219 OM PPFD2 0.916584580
## 334 OM PPFDROC 0.915490240
## 312 K PPFD6 0.915293137
## 226 Mn PPFD2 0.913180209
## 251 Aspect PPFD3 0.909833702
## 320 Aspect PPFD6 0.908862148
## 208 S PPFD1 0.907696330
## 145 OM S 0.900556470
## 197 N PPFD1 0.890044975
## 217 N PPFD2 0.876258644
## 89 Mg Al 0.875804231
## 36 C OM 0.870381763
## 392 Al TempMax 0.869873403
## 388 pH TempMax 0.862041805
## 477 K TempROC 0.854937969
## 210 Aspect PPFD1 0.852347647
## 228 S PPFD2 0.852227448
## 102 Mg Fe 0.851511523
## 464 TempMax TempMean 0.847998744
## 199 OM PPFD1 0.845972660
## 157 Bulb Slope 0.843384478
## 218 C PPFD2 0.836119841
## 198 C PPFD1 0.834057122
## 292 Mn PPFD5 0.833081341
## 393 Fe TempMax 0.822998531
## 298 PPFD2 PPFD5 0.817003490
## 243 K PPFD3 0.815636107
## 347 PPFD2 PPFDROC 0.808145589
## 391 Ca TempMax 0.804541734
## 323 PPFD3 PPFD6 0.794929233
## 293 P PPFD5 0.789373532
## 227 P PPFD2 0.777873799
## 461 PPFD6 TempMean 0.777726876
## 495 TempMin TempROC 0.774787377
## 183 K Aspect 0.772714726
## 446 Mg TempMean 0.768515525
## 6 Dry Bulb 0.765053708
## 273 Aspect PPFD4 0.763470099
## 289 Ca PPFD5 0.761717800
## 284 C PPFD5 0.761476310
## 281 BulbWidth PPFD5 0.760630832
## 418 K TempMin 0.757698844
## 434 WeeklyTempROC TempMin 0.756404113
## 491 PPFD6 TempROC 0.743033154
## 353 Fresh WeeklyTempROC 0.739608129
## 494 TempMax TempROC 0.733031548
## 132 K P 0.730431911
## 345 Aspect PPFDROC 0.725081812
## 31 Dry OM 0.719938826
## 380 Fresh TempMax 0.718291454
## 274 PPFD1 PPFD4 0.716973854
## 8 Fresh BulbWidth 0.712091636
## 252 PPFD1 PPFD3 0.709266248
## 283 N PPFD5 0.708507196
## 191 Allicin PPFD1 0.706904443
## 213 Dry PPFD2 0.677144644
## 481 Mn TempROC 0.676259523
## 156 Dry Slope 0.675162422
## 114 OM Mn 0.674058150
## 280 Bulb PPFD5 0.670789098
## 482 P TempROC 0.664678110
## 285 OM PPFD5 0.664671625
## 437 Fresh TempMean 0.664354933
## 172 Allicin Aspect 0.657956908
## 113 C Mn 0.656592080
## 152 Mn S 0.655016018
## 26 BulbWidth C 0.649550607
## 71 BulbWidth Ca 0.646949529
## 286 pH PPFD5 0.645426164
## 231 PPFD1 PPFD2 0.644116903
## 255 Fresh PPFD4 0.643301310
## 294 S PPFD5 0.641467638
## 110 BulbWidth Mn 0.639630634
## 455 Aspect TempMean 0.639320694
## 125 BulbWidth P 0.638022516
## 189 S Aspect 0.636950158
## 112 N Mn 0.636743489
## 80 Fresh Al 0.636148341
## 178 N Aspect 0.634187475
## 404 PPFD6 TempMax 0.632282555
## 350 PPFD5 PPFDROC 0.632067983
## 50 BulbWidth Mg 0.628360484
## 287 Mg PPFD5 0.626579694
## 476 Mg TempROC 0.615583990
## 248 P PPFD3 0.613942437
## 179 C Aspect 0.611200338
## 47 Fresh Mg 0.610342345
## 117 K Mn 0.608256316
## 443 C TempMean 0.604745369
## 479 Al TempROC 0.603660797
## 311 Mg PPFD6 0.600950437
## 18 Dry N 0.600511888
## 480 Fe TempROC 0.595822405
## 279 Dry PPFD5 0.594531276
## 321 PPFD1 PPFD6 0.593086072
## 265 K PPFD4 0.587815147
## 232 Allicin PPFD3 0.585456352
## 41 BulbWidth pH 0.583086471
## 423 P TempMin 0.582631157
## 53 C Mg 0.572399728
## 215 BulbWidth PPFD2 0.569499028
## 38 Fresh pH 0.567943075
## 487 PPFD2 TempROC 0.566869065
## 254 Allicin PPFD4 0.561723057
## 93 Fresh Fe 0.560989855
## 475 pH TempROC 0.560593707
## 341 Mn PPFDROC 0.558781339
## 262 OM PPFD4 0.555961001
## 326 Allicin PPFDROC 0.554611821
## 463 WeeklyTempROC TempMean 0.552982007
## 137 Allicin S 0.551966983
## 141 BulbWidth S 0.551183728
## 422 Mn TempMin 0.550520050
## 454 Slope TempMean 0.549550252
## 462 PPFDROC TempMean 0.544149052
## 496 TempMean TempROC 0.541050318
## 295 Slope PPFD5 0.540086066
## 375 PPFD4 WeeklyTempROC 0.534083927
## 68 Fresh Ca 0.533542367
## 324 PPFD4 PPFD6 0.533302075
## 368 P WeeklyTempROC 0.532007038
## 70 Bulb Ca 0.531854852
## 421 Fe TempMin 0.531334284
## 453 S TempMean 0.530318978
## 351 PPFD6 PPFDROC 0.524890367
## 383 BulbWidth TempMax 0.523782447
## 20 BulbWidth N 0.521701014
## 108 Dry Mn 0.519402464
## 445 pH TempMean 0.517906055
## 180 OM Aspect 0.516786383
## 330 BulbWidth PPFDROC 0.512455572
## 83 BulbWidth Al 0.511538273
## 291 Fe PPFD5 0.510032052
## 370 Slope WeeklyTempROC 0.509124429
## 356 BulbWidth WeeklyTempROC 0.505934297
## 447 K TempMean 0.505831722
## 267 Al PPFD4 0.504413801
## 349 PPFD4 PPFDROC 0.503772494
## 290 Al PPFD5 0.502739972
## 390 K TempMax 0.501911458
## 317 P PPFD6 0.499212716
## 348 PPFD3 PPFDROC 0.498740873
## 416 pH TempMin 0.498681989
## 109 Bulb Mn 0.498634563
## 440 BulbWidth TempMean 0.497053634
## 260 N PPFD4 0.492924488
## 124 Bulb P 0.491940674
## 449 Al TempMean 0.490186028
## 128 C P 0.489017338
## 259 SLA PPFD4 0.488848326
## 16 Allicin N 0.486592930
## 448 Ca TempMean 0.485139225
## 328 Dry PPFDROC 0.482955466
## 432 PPFD6 TempMin 0.481527906
## 214 Bulb PPFD2 0.479760565
## 96 BulbWidth Fe 0.477360866
## 154 Allicin Slope 0.474606286
## 190 Slope Aspect 0.472459911
## 66 Mg K 0.472268895
## 268 Fe PPFD4 0.471572987
## 456 PPFD1 TempMean 0.470377148
## 153 P S 0.467587307
## 420 Al TempMin 0.467494511
## 308 C PPFD6 0.466250078
## 74 C Ca 0.464603199
## 367 Mn WeeklyTempROC 0.464252926
## 129 OM P 0.462381303
## 24 Dry C 0.460967328
## 319 Slope PPFD6 0.460395138
## 270 P PPFD4 0.454708852
## 237 SLA PPFD3 0.454546956
## 29 Allicin OM 0.453970161
## 301 Allicin PPFD6 0.451415040
## 336 Mg PPFDROC 0.445037769
## 22 Allicin C 0.444398278
## 92 Allicin Fe 0.443446087
## 40 Bulb pH 0.442353413
## 478 Ca TempROC 0.440253091
## 419 Ca TempMin 0.436965803
## 238 N PPFD3 0.436316862
## 166 Ca Slope 0.435537331
## 139 Dry S 0.433195470
## 196 SLA PPFD1 0.432484330
## 127 N P 0.432205858
## 429 PPFD3 TempMin 0.428347595
## 417 Mg TempMin 0.423269762
## 442 N TempMean 0.422945058
## 10 Bulb BulbWidth 0.420987593
## 307 N PPFD6 0.418093246
## 52 N Mg 0.415254347
## 485 Aspect TempROC 0.413859862
## 233 Fresh PPFD3 0.413301260
## 177 SLA Aspect 0.412306116
## 318 S PPFD6 0.412107545
## 170 P Slope 0.410429174
## 374 PPFD3 WeeklyTempROC 0.409002588
## 450 Fe TempMean 0.408498547
## 363 K WeeklyTempROC 0.408337817
## 79 Allicin Al 0.406978325
## 95 Bulb Fe 0.405821932
## 488 PPFD3 TempROC 0.404437802
## 33 BulbWidth OM 0.404431030
## 240 OM PPFD3 0.403085843
## 271 S PPFD4 0.396113126
## 247 Mn PPFD3 0.392382910
## 9 Dry BulbWidth 0.389947507
## 123 Dry P 0.388708432
## 256 Dry PPFD4 0.387009632
## 386 C TempMax 0.385907449
## 354 Dry WeeklyTempROC 0.385169269
## 369 S WeeklyTempROC 0.384458361
## 169 Mn Slope 0.384383323
## 403 PPFD5 TempMax 0.383477570
## 32 Bulb OM 0.383354016
## 147 Mg S 0.377984643
## 188 P Aspect 0.377371235
## 249 S PPFD3 0.375997233
## 168 Fe Slope 0.372556365
## 428 PPFD2 TempMin 0.372360059
## 435 TempMax TempMin 0.369012358
## 193 Dry PPFD1 0.366853462
## 474 OM TempROC 0.363564867
## 122 Fresh P 0.358403717
## 163 pH Slope 0.356892259
## 182 Mg Aspect 0.356824914
## 44 C pH 0.355445281
## 202 K PPFD1 0.354845932
## 316 Mn PPFD6 0.354409531
## 278 Fresh PPFD5 0.353570979
## 359 C WeeklyTempROC 0.352057860
## 342 P PPFDROC 0.351864894
## 263 pH PPFD4 0.347326756
## 4 Allicin Bulb 0.346866663
## 133 Ca P 0.345351578
## 425 Slope TempMin 0.342172967
## 82 Bulb Al 0.338707676
## 250 Slope PPFD3 0.337565346
## 310 pH PPFD6 0.336702258
## 73 N Ca 0.335223166
## 3 Fresh Dry 0.334231846
## 436 Allicin TempMean 0.333717452
## 229 Slope PPFD2 0.333296657
## 84 SLA Al 0.330496389
## 97 SLA Fe 0.329299745
## 239 C PPFD3 0.326449659
## 206 Mn PPFD1 0.325955724
## 468 Dry TempROC 0.325691610
## 398 Aspect TempMax 0.325585880
## 406 WeeklyTempROC TempMax 0.324527370
## 205 Fe PPFD1 0.320416808
## 430 PPFD4 TempMin 0.319460158
## 297 PPFD1 PPFD5 0.316216711
## 34 SLA OM 0.315692868
## 118 Ca Mn 0.313535668
## 37 Allicin pH 0.312387753
## 331 SLA PPFDROC 0.311022118
## 261 C PPFD4 0.309377051
## 222 K PPFD2 0.307006634
## 266 Ca PPFD4 0.304565255
## 65 pH K 0.304060153
## 338 Ca PPFDROC 0.303703758
## 19 Bulb N 0.302795381
## 355 Bulb WeeklyTempROC 0.302596379
## 458 PPFD3 TempMean 0.301187655
## 258 BulbWidth PPFD4 0.300398722
## 204 Al PPFD1 0.292639283
## 313 Ca PPFD6 0.292442938
## 424 S TempMin 0.291524610
## 21 SLA N 0.291426243
## 209 Slope PPFD1 0.289317691
## 245 Al PPFD3 0.289006293
## 246 Fe PPFD3 0.282162710
## 142 SLA S 0.281801330
## 56 Allicin K 0.280348520
## 167 Al Slope 0.279843619
## 439 Bulb TempMean 0.278865519
## 67 Allicin Ca 0.277084962
## 460 PPFD5 TempMean 0.274802012
## 304 Bulb PPFD6 0.273692365
## 211 Allicin PPFD2 0.273236018
## 165 K Slope 0.272476186
## 223 Ca PPFD2 0.272144100
## 175 Bulb Aspect 0.271068407
## 438 Dry TempMean 0.270918435
## 402 PPFD4 TempMax 0.270140427
## 23 Fresh C 0.267154585
## 373 PPFD2 WeeklyTempROC 0.262392649
## 49 Bulb Mg 0.261696718
## 155 Fresh Slope 0.259274382
## 314 Al PPFD6 0.259266955
## 306 SLA PPFD6 0.259244127
## 405 PPFDROC TempMax 0.257220539
## 69 Dry Ca 0.256471029
## 103 K Fe 0.253504161
## 195 BulbWidth PPFD1 0.253443850
## 42 SLA pH 0.252951716
## 410 Bulb TempMin 0.252944980
## 337 K PPFDROC 0.251193480
## 90 K Al 0.249903622
## 426 Aspect TempMin 0.249631943
## 235 Bulb PPFD3 0.247803334
## 25 Bulb C 0.247338400
## 13 Dry SLA 0.245843369
## 107 Fresh Mn 0.245559717
## 493 WeeklyTempROC TempROC 0.245066447
## 149 Ca S 0.244683401
## 376 PPFD5 WeeklyTempROC 0.243832418
## 14 Bulb SLA 0.242736810
## 236 BulbWidth PPFD3 0.241233492
## 378 PPFDROC WeeklyTempROC 0.237855070
## 78 K Ca 0.233832043
## 467 Fresh TempROC 0.233387133
## 309 OM PPFD6 0.230846720
## 162 OM Slope 0.230808475
## 61 SLA K 0.228490767
## 483 S TempROC 0.228077381
## 408 Fresh TempMin 0.226917536
## 484 Slope TempROC 0.226215743
## 315 Fe PPFD6 0.225820494
## 72 SLA Ca 0.224803226
## 130 pH P 0.222376818
## 1 Allicin Fresh 0.220153619
## 299 PPFD3 PPFD5 0.219248224
## 11 Allicin SLA 0.216454209
## 381 Dry TempMax 0.215797493
## 269 Mn PPFD4 0.213868290
## 27 SLA C 0.211339155
## 43 N pH 0.208306770
## 396 S TempMax 0.206322981
## 362 Mg WeeklyTempROC 0.206289363
## 201 Mg PPFD1 0.200966071
## 54 OM Mg 0.200719976
## 221 Mg PPFD2 0.198723232
## 230 Aspect PPFD2 0.198671814
## 59 Bulb K 0.197925820
## 407 Allicin TempMin 0.197710230
## 335 pH PPFDROC 0.193640728
## 275 PPFD2 PPFD4 0.191002653
## 490 PPFD5 TempROC 0.190520267
## 469 Bulb TempROC 0.188076970
## 75 OM Ca 0.187368877
## 385 N TempMax 0.184562396
## 87 OM Al 0.183758852
## 288 K PPFD5 0.183738649
## 472 N TempROC 0.178004449
## 411 BulbWidth TempMin 0.177099972
## 62 N K 0.173342758
## 30 Fresh OM 0.172147113
## 100 OM Fe 0.172034260
## 329 Bulb PPFDROC 0.170309435
## 86 C Al 0.169748869
## 159 SLA Slope 0.169249743
## 126 SLA P 0.169150398
## 115 pH Mn 0.168272401
## 244 Ca PPFD3 0.168028398
## 409 Dry TempMin 0.167211619
## 63 C K 0.166665732
## 444 OM TempMean 0.165917099
## 138 Fresh S 0.165256640
## 241 pH PPFD3 0.164870197
## 397 Slope TempMax 0.164308368
## 116 Mg Mn 0.163012079
## 187 Mn Aspect 0.161345747
## 384 SLA TempMax 0.160138161
## 358 N WeeklyTempROC 0.158127204
## 134 Al P 0.156793388
## 300 PPFD4 PPFD5 0.156521653
## 234 Dry PPFD3 0.156474010
## 131 Mg P 0.152847790
## 216 SLA PPFD2 0.151545984
## 15 BulbWidth SLA 0.151493866
## 352 Allicin WeeklyTempROC 0.150326628
## 264 Mg PPFD4 0.149336150
## 158 BulbWidth Slope 0.148676073
## 302 Fresh PPFD6 0.147286865
## 135 Fe P 0.144242442
## 414 C TempMin 0.139434857
## 372 PPFD1 WeeklyTempROC 0.139428414
## 99 C Fe 0.138770797
## 60 BulbWidth K 0.133253969
## 140 Bulb S 0.133191348
## 427 PPFD1 TempMin 0.132694616
## 415 OM TempMin 0.132099296
## 357 SLA WeeklyTempROC 0.129259328
## 39 Dry pH 0.129258193
## 121 Allicin P 0.128253723
## 146 pH S 0.127521087
## 365 Al WeeklyTempROC 0.126001116
## 186 Fe Aspect 0.125629652
## 171 S Slope 0.117486534
## 51 SLA Mg 0.115978341
## 433 PPFDROC TempMin 0.113421519
## 305 BulbWidth PPFD6 0.113153231
## 220 pH PPFD2 0.112324634
## 272 Slope PPFD4 0.111284956
## 7 Allicin BulbWidth 0.108882161
## 457 PPFD2 TempMean 0.108827215
## 200 pH PPFD1 0.105242134
## 192 Fresh PPFD1 0.103141944
## 327 Fresh PPFDROC 0.098190387
## 492 PPFDROC TempROC 0.096258667
## 174 Dry Aspect 0.095965848
## 185 Al Aspect 0.095660395
## 151 Fe S 0.094944975
## 148 K S 0.093856154
## 413 N TempMin 0.092731882
## 489 PPFD4 TempROC 0.092034360
## 160 N Slope 0.091445599
## 486 PPFD1 TempROC 0.090031991
## 57 Fresh K 0.089700300
## 303 Dry PPFD6 0.089471304
## 242 Mg PPFD3 0.086717367
## 207 P PPFD1 0.086592772
## 164 Mg Slope 0.086547521
## 5 Fresh Bulb 0.085341249
## 282 SLA PPFD5 0.084852331
## 473 C TempROC 0.084488449
## 364 Ca WeeklyTempROC 0.083582990
## 48 Dry Mg 0.082714502
## 257 Bulb PPFD4 0.076842325
## 224 Al PPFD2 0.074867298
## 225 Fe PPFD2 0.073629273
## 361 pH WeeklyTempROC 0.072925584
## 176 BulbWidth Aspect 0.072015222
## 344 Slope PPFDROC 0.070518750
## 194 Bulb PPFD1 0.068198612
## 387 OM TempMax 0.068093215
## 173 Fresh Aspect 0.067121118
## 399 PPFD1 TempMax 0.066328833
## 322 PPFD2 PPFD6 0.063842640
## 400 PPFD2 TempMax 0.063098606
## 277 Allicin PPFD5 0.062732099
## 58 Dry K 0.061170266
## 150 Al S 0.058270474
## 379 Allicin TempMax 0.058054273
## 466 Allicin TempROC 0.056340340
## 81 Dry Al 0.051491448
## 441 SLA TempMean 0.050537583
## 119 Al Mn 0.050449225
## 470 BulbWidth TempROC 0.047557127
## 394 Mn TempMax 0.047498829
## 46 Allicin Mg 0.046680722
## 184 Ca Aspect 0.046635768
## 377 PPFD6 WeeklyTempROC 0.046023898
## 401 PPFD3 TempMax 0.045890696
## 431 PPFD5 TempMin 0.042485778
## 111 SLA Mn 0.042484889
## 120 Fe Mn 0.041219969
## 64 OM K 0.040400766
## 45 OM pH 0.040112508
## 106 Allicin Mn 0.039883708
## 371 Aspect WeeklyTempROC 0.039815297
## 471 SLA TempROC 0.039037528
## 465 TempMin TempMean 0.038918893
## 212 Fresh PPFD2 0.038735123
## 181 pH Aspect 0.037774953
## 12 Fresh SLA 0.032502691
## 17 Fresh N 0.032199269
## 340 Fe PPFDROC 0.032093475
## 451 Mn TempMean 0.029673137
## 296 Aspect PPFD5 0.025746113
## 366 Fe WeeklyTempROC 0.025512240
## 2 Allicin Dry 0.025336826
## 452 P TempMean 0.020455559
## 360 OM WeeklyTempROC 0.017034720
## 203 Ca PPFD1 0.015169927
## 98 N Fe 0.015125215
## 94 Dry Fe 0.014821113
## 395 P TempMax 0.012522711
## 382 Bulb TempMax 0.010978103
## 253 PPFD2 PPFD3 0.010371619
## 412 SLA TempMin 0.007534375
## 339 Al PPFDROC 0.006978314
## 459 PPFD4 TempMean 0.006930279
## 85 N Al 0.005573191
## 161 C Slope 0.004323980
## 325 PPFD5 PPFD6 0.001670669
Intersite Variability:
#Load and read data
Response_Raw <- read_csv("Data/Response_Raw.csv")
R_data <- Response_Raw
response_columns <- names(R_data)[-1] # Exclude the first column (Site)
# Loop through each response variable
for (col in response_columns) {
# Subset data for the current response variable
response_data <- R_data[, c("Site", col)]
# Residual histogram
hist(residuals(lm(as.formula(paste(col, "~ Site")), data = response_data)),
xlab = "Residuals", main = paste("Residual Distribution for", col))
# Boxplot
boxplot(response_data[[col]] ~ response_data$Site,
xlab = "Site", ylab = "Residuals",
main = paste("Boxplot of", col, "by Site"))
# Intrasite Variability
variance_within <- tapply(response_data[[col]], response_data$Site, var)
cat("Intrasite Variation of", col, ":\n")
print(variance_within)
#Bartlett's test
bartlett_result <- bartlett.test(response_data[[col]], response_data$Site)
cat("\nBartlett's Test of Homogeneity:\n")
print(bartlett_result)
# Intersite Variability (ANOVA F-test)
anova_result <- aov(as.formula(paste(col, "~ Site")), data = response_data)
anova_table <- anova(anova_result)
print(anova_table)
# Protected LSD test
lsd_result <- LSD.test(anova_result, "Site", console = TRUE)
}
## Intrasite Variation of Allicin :
## CF CFUA PF RT SQAP
## 3049469.7 740432.2 855250.0 376154.4 6638922.2
##
## Bartlett's Test of Homogeneity:
##
## Bartlett test of homogeneity of variances
##
## data: response_data[[col]] and response_data$Site
## Bartlett's K-squared = 22.925, df = 4, p-value = 0.0001311
##
## Analysis of Variance Table
##
## Response: Allicin
## Df Sum Sq Mean Sq F value Pr(>F)
## Site 4 72446429 18111607 7.7664 7.563e-05 ***
## Residuals 45 104942056 2332046
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Study: anova_result ~ "Site"
##
## LSD t Test for Allicin
##
## Mean Square Error: 2332046
##
## Site, means and individual ( 95 %) CI
##
## Allicin std r se LCL UCL Min Max
## CF 3259.098 1746.2731 10 482.9126 2286.46212 4231.734 1602.50 7245.05
## CFUA 1491.579 860.4837 10 482.9126 518.94312 2464.215 322.05 2997.45
## PF 1302.571 924.7973 10 482.9126 329.93512 2275.207 103.23 2631.26
## RT 1035.749 613.3143 10 482.9126 63.11312 2008.385 151.45 2192.45
## SQAP 4061.386 2576.6106 10 482.9126 3088.75012 5034.022 1272.61 10675.37
## Q25 Q50 Q75
## CF 2149.470 2908.835 3069.265
## CFUA 803.655 1363.415 2104.235
## PF 459.255 1249.825 2103.580
## RT 586.295 897.365 1474.963
## SQAP 3403.092 3551.625 3971.457
##
## Alpha: 0.05 ; DF Error: 45
## Critical Value of t: 2.014103
##
## least Significant Difference: 1375.515
##
## Treatments with the same letter are not significantly different.
##
## Allicin groups
## SQAP 4061.386 a
## CF 3259.098 a
## CFUA 1491.579 b
## PF 1302.571 b
## RT 1035.749 b
## Intrasite Variation of Dry :
## CF CFUA PF RT SQAP
## 0.34742738 0.11831551 0.08875573 0.52768693 0.08082427
##
## Bartlett's Test of Homogeneity:
##
## Bartlett test of homogeneity of variances
##
## data: response_data[[col]] and response_data$Site
## Bartlett's K-squared = 12.719, df = 4, p-value = 0.01273
##
## Analysis of Variance Table
##
## Response: Dry
## Df Sum Sq Mean Sq F value Pr(>F)
## Site 4 8.7325 2.1831 9.3857 1.326e-05 ***
## Residuals 45 10.4671 0.2326
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Study: anova_result ~ "Site"
##
## LSD t Test for Dry
##
## Mean Square Error: 0.232602
##
## Site, means and individual ( 95 %) CI
##
## Dry std r se LCL UCL Min Max Q25
## CF 2.0204 0.5894297 10 0.1525129 1.7132232 2.327577 0.953 2.902 1.63775
## CFUA 1.6052 0.3439702 10 0.1525129 1.2980232 1.912377 1.133 2.234 1.36450
## PF 1.2828 0.2979190 10 0.1525129 0.9756232 1.589977 0.773 1.715 1.09750
## RT 2.4516 0.7264206 10 0.1525129 2.1444232 2.758777 1.490 3.732 1.88200
## SQAP 1.4846 0.2842961 10 0.1525129 1.1774232 1.791777 1.004 1.990 1.30050
## Q50 Q75
## CF 2.2795 2.33675
## CFUA 1.5965 1.75800
## PF 1.2375 1.54600
## RT 2.2980 2.98325
## SQAP 1.5460 1.60750
##
## Alpha: 0.05 ; DF Error: 45
## Critical Value of t: 2.014103
##
## least Significant Difference: 0.4344136
##
## Treatments with the same letter are not significantly different.
##
## Dry groups
## RT 2.4516 a
## CF 2.0204 ab
## CFUA 1.6052 bc
## SQAP 1.4846 c
## PF 1.2828 c
## Intrasite Variation of Fresh :
## CF CFUA PF RT SQAP
## 7.0200046 1.2247817 0.9915282 1.5601178 1.3174586
##
## Bartlett's Test of Homogeneity:
##
## Bartlett test of homogeneity of variances
##
## data: response_data[[col]] and response_data$Site
## Bartlett's K-squared = 13.452, df = 4, p-value = 0.009266
##
## Analysis of Variance Table
##
## Response: Fresh
## Df Sum Sq Mean Sq F value Pr(>F)
## Site 4 217.98 54.495 22.493 2.957e-10 ***
## Residuals 45 109.03 2.423
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Study: anova_result ~ "Site"
##
## LSD t Test for Fresh
##
## Mean Square Error: 2.422778
##
## Site, means and individual ( 95 %) CI
##
## Fresh std r se LCL UCL Min Max Q25
## CF 10.9958 2.6495291 10 0.4922172 10.004424 11.987176 5.877 13.834 9.67800
## CFUA 10.2629 1.1066985 10 0.4922172 9.271524 11.254276 9.087 12.256 9.51725
## PF 6.0617 0.9957551 10 0.4922172 5.070324 7.053076 4.262 7.283 5.40675
## RT 10.6124 1.2490468 10 0.4922172 9.621024 11.603776 8.057 11.959 9.95625
## SQAP 6.7628 1.1478060 10 0.4922172 5.771424 7.754176 4.471 8.549 6.19525
## Q50 Q75
## CF 11.8665 12.84225
## CFUA 9.7710 10.86525
## PF 5.9895 6.89100
## RT 10.9805 11.61650
## SQAP 6.9345 7.45975
##
## Alpha: 0.05 ; DF Error: 45
## Critical Value of t: 2.014103
##
## least Significant Difference: 1.402018
##
## Treatments with the same letter are not significantly different.
##
## Fresh groups
## CF 10.9958 a
## RT 10.6124 a
## CFUA 10.2629 a
## SQAP 6.7628 b
## PF 6.0617 b
## Intrasite Variation of Bulb :
## CF CFUA PF RT SQAP
## 0.22481112 0.11644966 0.07365538 0.50808356 0.05966588
##
## Bartlett's Test of Homogeneity:
##
## Bartlett test of homogeneity of variances
##
## data: response_data[[col]] and response_data$Site
## Bartlett's K-squared = 13.896, df = 4, p-value = 0.007634
##
## Analysis of Variance Table
##
## Response: Bulb
## Df Sum Sq Mean Sq F value Pr(>F)
## Site 4 7.2085 1.80212 9.1696 1.661e-05 ***
## Residuals 45 8.8440 0.19653
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Study: anova_result ~ "Site"
##
## LSD t Test for Bulb
##
## Mean Square Error: 0.1965331
##
## Site, means and individual ( 95 %) CI
##
## Bulb std r se LCL UCL Min Max Q25
## CF 1.4163 0.4741425 10 0.1401903 1.1339423 1.698658 0.609 2.094 1.03500
## CFUA 1.0959 0.3412472 10 0.1401903 0.8135423 1.378258 0.685 1.727 0.83975
## PF 0.9736 0.2713952 10 0.1401903 0.6912423 1.255958 0.538 1.375 0.81100
## RT 2.0100 0.7127998 10 0.1401903 1.7276423 2.292358 1.157 3.311 1.48050
## SQAP 1.0639 0.2442660 10 0.1401903 0.7815423 1.346258 0.685 1.552 0.94025
## Q50 Q75
## CF 1.6315 1.73125
## CFUA 1.0540 1.30325
## PF 0.9015 1.20425
## RT 1.7550 2.52175
## SQAP 1.0295 1.20025
##
## Alpha: 0.05 ; DF Error: 45
## Critical Value of t: 2.014103
##
## least Significant Difference: 0.3993141
##
## Treatments with the same letter are not significantly different.
##
## Bulb groups
## RT 2.0100 a
## CF 1.4163 b
## CFUA 1.0959 bc
## SQAP 1.0639 bc
## PF 0.9736 c
## Intrasite Variation of BulbWidth :
## CF CFUA PF RT SQAP
## 4.980072 1.580668 3.841982 1.403912 2.583716
##
## Bartlett's Test of Homogeneity:
##
## Bartlett test of homogeneity of variances
##
## data: response_data[[col]] and response_data$Site
## Bartlett's K-squared = 5.0653, df = 4, p-value = 0.2807
##
## Analysis of Variance Table
##
## Response: BulbWidth
## Df Sum Sq Mean Sq F value Pr(>F)
## Site 4 98.037 24.5092 8.5159 3.326e-05 ***
## Residuals 45 129.513 2.8781
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Study: anova_result ~ "Site"
##
## LSD t Test for BulbWidth
##
## Mean Square Error: 2.87807
##
## Site, means and individual ( 95 %) CI
##
## BulbWidth std r se LCL UCL Min Max Q25
## CF 15.345 2.231608 10 0.5364765 14.26448 16.42552 11.05 17.54 13.5400
## CFUA 13.627 1.257246 10 0.5364765 12.54648 14.70752 11.60 15.30 12.8725
## PF 12.574 1.960098 10 0.5364765 11.49348 13.65452 8.87 15.17 11.5975
## RT 16.603 1.184868 10 0.5364765 15.52248 17.68352 14.69 17.90 15.9100
## SQAP 14.036 1.607394 10 0.5364765 12.95548 15.11652 12.18 17.24 12.8025
## Q50 Q75
## CF 16.535 16.9525
## CFUA 13.830 14.5850
## PF 12.390 14.0325
## RT 16.540 17.7225
## SQAP 13.785 14.5750
##
## Alpha: 0.05 ; DF Error: 45
## Critical Value of t: 2.014103
##
## least Significant Difference: 1.528085
##
## Treatments with the same letter are not significantly different.
##
## BulbWidth groups
## RT 16.603 a
## CF 15.345 ab
## SQAP 14.036 bc
## CFUA 13.627 c
## PF 12.574 c
## Intrasite Variation of SLA :
## CF CFUA PF RT SQAP
## 10489.724 1173.429 3888.297 5612.422 4198.925
##
## Bartlett's Test of Homogeneity:
##
## Bartlett test of homogeneity of variances
##
## data: response_data[[col]] and response_data$Site
## Bartlett's K-squared = 9.4022, df = 4, p-value = 0.0518
##
## Analysis of Variance Table
##
## Response: SLA
## Df Sum Sq Mean Sq F value Pr(>F)
## Site 4 44752 11188.0 2.2056 0.08349 .
## Residuals 45 228265 5072.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Study: anova_result ~ "Site"
##
## LSD t Test for SLA
##
## Mean Square Error: 5072.559
##
## Site, means and individual ( 95 %) CI
##
## SLA std r se LCL UCL Min Max
## CF 255.3110 102.41935 10 22.52234 209.9487 300.6733 125.1610 495.7558
## CFUA 299.5497 34.25535 10 22.52234 254.1873 344.9120 243.6891 363.5793
## PF 266.6448 62.35621 10 22.52234 221.2824 312.0071 165.8875 368.7149
## RT 301.3490 74.91610 10 22.52234 255.9866 346.7113 184.2044 443.6877
## SQAP 221.0126 64.79911 10 22.52234 175.6502 266.3749 153.8707 338.2848
## Q25 Q50 Q75
## CF 207.0494 226.8085 288.0627
## CFUA 280.8863 300.0421 316.2148
## PF 239.0989 252.7509 287.2056
## RT 274.2705 297.5297 332.6769
## SQAP 172.7952 198.9615 270.9622
##
## Alpha: 0.05 ; DF Error: 45
## Critical Value of t: 2.014103
##
## least Significant Difference: 64.15202
##
## Treatments with the same letter are not significantly different.
##
## SLA groups
## RT 301.3490 a
## CFUA 299.5497 a
## PF 266.6448 ab
## CF 255.3110 ab
## SQAP 221.0126 b
#SLA - rt/cfua/pf vs pf/cf/sqap, not significantly different between sites
#bulbwidth - rt/cf, cf/sqap, sqap/cfua/pf, significant
#bulbmass - rt, cf/cfua/sqap, cfua/sqap/pf, sig
#fresh - cf/rt/cfua, sqap/pf, significant
#dry - rt/cf, cf/cfua, cfua/sqap/pf,sig
#allicin - sqap/cf, cfua/pf/rt, sig
library(ggplot2)
#*Using log transformed and standardized data, univariate regression analyses are used to understand individual relationships between biological response variables and each environmental parameter.*
# Define response and predictor variables
response_var <- colnames(logzdata)[1:6]
env_var <- colnames(logzdata)[7:32]
# Empty data frame to store results
results_table <- data.frame(Response_Variable = character(),
Predictor_Variable = character(),
Coefficient = numeric(),
Std_Error = numeric(),
t_value = numeric(),
p_value = numeric(),
RSquared = numeric(), # Add a column for R^2
stringsAsFactors = FALSE)
# Perform regression analysis for each response variable and predictor variable
for (response in response_var) {
for (env in env_var) {
model <- lm(logzdata[[response]] ~ logzdata[[env]])
# Results stored in the table
results_table <- rbind(results_table, data.frame(Response_Variable = response,
Predictor_Variable = env,
Coefficient = coef(model)[2],
Std_Error = summary(model)$coefficients[2, 2],
t_value = summary(model)$coefficients[2, 3],
p_value = summary(model)$coefficients[2, 4],
RSquared = summary(model)$r.squared))
}
}
significant_results <- results_table[results_table$p_value < 0.05, ]
# Highlighting the table based on conditions
library(DT)
## Warning: package 'DT' was built under R version 4.4.3
#Hide column names
rownames(results_table) <- NULL
# Highlight R^2 > 0.3 and p-values < 0.05
datatable(results_table, options = list(
columnDefs = list(
list(
targets = 7, # R_squared column index
render = JS("function(data, type, row, meta) {",
"if (parseFloat(data) > 0.3) {",
"return '<span style=\"color: red;\">' + data + '</span>';",
"} else {",
"return data;",
"}",
"}")
),
list(
targets = 6, # p_value column index
render = JS("function(data, type, row, meta) {",
"if (parseFloat(data) < 0.05) {",
"return '<span style=\"color: blue;\">' + data + '</span>';",
"} else {",
"return data;",
"}",
"}")
)
),
dom = 'tip',
pageLength = 10,
lengthMenu = c(10, 20, 50),
scrollX = TRUE,
width = "80%"
))
# Print the new table
print(significant_results)
## Response_Variable Predictor_Variable Coefficient Std_Error
## logzdata[[env]] Allicin N 0.4246413 0.1887810
## logzdata[[env]]8 Allicin Fe 0.4213353 0.1891028
## logzdata[[env]]11 Allicin S 0.4718604 0.1838416
## logzdata[[env]]12 Allicin Slope -0.4530981 0.1858824
## logzdata[[env]]13 Allicin Aspect 0.6555867 0.1574534
## logzdata[[env]]14 Allicin PPFD1 -0.7026116 0.1483733
## logzdata[[env]]16 Allicin PPFD3 0.6311119 0.1617429
## logzdata[[env]]17 Allicin PPFD4 0.5279073 0.1770917
## logzdata[[env]]19 Allicin PPFD6 0.5408952 0.1753794
## logzdata[[env]]20 Allicin PPFDROC -0.5433948 0.1750431
## logzdata[[env]]29 Fresh pH 0.5399799 0.1755020
## logzdata[[env]]30 Fresh Mg 0.5576997 0.1730759
## logzdata[[env]]32 Fresh Ca 0.4796472 0.1829634
## logzdata[[env]]33 Fresh Al -0.6416423 0.1599314
## logzdata[[env]]34 Fresh Fe -0.5604341 0.1726914
## logzdata[[env]]36 Fresh P 0.4502532 0.1861827
## logzdata[[env]]38 Fresh Slope -0.4161540 0.1896009
## logzdata[[env]]42 Fresh PPFD3 -0.4865454 0.1821697
## logzdata[[env]]43 Fresh PPFD4 -0.5734027 0.1708304
## logzdata[[env]]47 Fresh WeeklyTempROC -0.7691628 0.1332517
## logzdata[[env]]48 Fresh TempMax -0.6958627 0.1497498
## logzdata[[env]]50 Fresh TempMean -0.6516016 0.1581710
## logzdata[[env]]52 Dry N 0.6058873 0.1658837
## logzdata[[env]]53 Dry C 0.4705167 0.1839913
## logzdata[[env]]54 Dry OM 0.7331609 0.1418013
## logzdata[[env]]61 Dry Mn 0.4719690 0.1838295
## logzdata[[env]]63 Dry S 0.4324705 0.1880066
## logzdata[[env]]64 Dry Slope 0.7026226 0.1483711
## logzdata[[env]]67 Dry PPFD2 -0.6782940 0.1532144
## logzdata[[env]]69 Dry PPFD4 0.4920207 0.1815292
## logzdata[[env]]70 Dry PPFD5 0.6902655 0.1508719
## logzdata[[env]]72 Dry PPFDROC -0.4497712 0.1862334
## logzdata[[env]]73 Dry WeeklyTempROC 0.4026668 0.1908630
## logzdata[[env]]80 Bulb OM 0.4093261 0.1902461
## logzdata[[env]]81 Bulb pH 0.4244042 0.1888041
## logzdata[[env]]84 Bulb Ca 0.4888542 0.1819008
## logzdata[[env]]86 Bulb Fe -0.4698469 0.1840657
## logzdata[[env]]87 Bulb Mn 0.4293479 0.1883175
## logzdata[[env]]90 Bulb Slope 0.7926278 0.1271324
## logzdata[[env]]93 Bulb PPFD2 -0.4913084 0.1816131
## logzdata[[env]]96 Bulb PPFD5 0.5928851 0.1679140
## logzdata[[env]]104 BulbWidth N 0.5283751 0.1770310
## logzdata[[env]]105 BulbWidth C 0.6542419 0.1576964
## logzdata[[env]]106 BulbWidth OM 0.4165032 0.1895676
## logzdata[[env]]107 BulbWidth pH 0.5390573 0.1756252
## logzdata[[env]]108 BulbWidth Mg 0.5894608 0.1684373
## logzdata[[env]]110 BulbWidth Ca 0.5435427 0.1750232
## logzdata[[env]]111 BulbWidth Al -0.6064347 0.1657968
## logzdata[[env]]112 BulbWidth Fe -0.5593188 0.1728486
## logzdata[[env]]113 BulbWidth Mn 0.6394049 0.1603205
## logzdata[[env]]114 BulbWidth P 0.6151322 0.1643978
## logzdata[[env]]115 BulbWidth S 0.5854400 0.1690459
## logzdata[[env]]119 BulbWidth PPFD2 -0.5574052 0.1731171
## logzdata[[env]]122 BulbWidth PPFD5 0.6474067 0.1589182
## logzdata[[env]]124 BulbWidth PPFDROC -0.4970249 0.1809355
## logzdata[[env]]125 BulbWidth WeeklyTempROC -0.5155645 0.1786657
## logzdata[[env]]126 BulbWidth TempMax -0.5203055 0.1780672
## logzdata[[env]]128 BulbWidth TempMean -0.5051074 0.1799597
## logzdata[[env]]143 SLA Aspect -0.4565214 0.1855179
## logzdata[[env]]144 SLA PPFD1 0.4704450 0.1839992
## logzdata[[env]]146 SLA PPFD3 -0.4602045 0.1851218
## logzdata[[env]]147 SLA PPFD4 -0.4604280 0.1850976
## t_value p_value RSquared
## logzdata[[env]] 2.249386 3.436035e-02 0.1803202
## logzdata[[env]]8 2.228076 3.593963e-02 0.1775234
## logzdata[[env]]11 2.566669 1.724709e-02 0.2226523
## logzdata[[env]]12 -2.437553 2.293133e-02 0.2052979
## logzdata[[env]]13 4.163687 3.744138e-04 0.4297939
## logzdata[[env]]14 -4.735431 9.001413e-05 0.4936631
## logzdata[[env]]16 3.901945 7.174347e-04 0.3983023
## logzdata[[env]]17 2.980983 6.681815e-03 0.2786862
## logzdata[[env]]19 3.084144 5.240706e-03 0.2925676
## logzdata[[env]]20 -3.104349 4.995833e-03 0.2952780
## logzdata[[env]]29 3.076774 5.332866e-03 0.2915783
## logzdata[[env]]30 3.222284 3.772196e-03 0.3110289
## logzdata[[env]]32 2.621548 1.525483e-02 0.2300614
## logzdata[[env]]33 -4.011985 5.460443e-04 0.4117049
## logzdata[[env]]34 -3.245292 3.569908e-03 0.3140863
## logzdata[[env]]36 2.418340 2.391239e-02 0.2027279
## logzdata[[env]]38 -2.194894 3.853029e-02 0.1731841
## logzdata[[env]]42 -2.670835 1.365155e-02 0.2367264
## logzdata[[env]]43 -3.356562 2.731026e-03 0.3287906
## logzdata[[env]]47 -5.772253 7.020578e-06 0.5916113
## logzdata[[env]]48 -4.646835 1.122434e-04 0.4842248
## logzdata[[env]]50 -4.119603 4.178458e-04 0.4245846
## logzdata[[env]]52 3.652481 1.327660e-03 0.3670994
## logzdata[[env]]53 2.557278 1.761148e-02 0.2213860
## logzdata[[env]]54 5.170339 3.060253e-05 0.5375249
## logzdata[[env]]61 2.567428 1.721793e-02 0.2227547
## logzdata[[env]]63 2.300294 3.084038e-02 0.1870307
## logzdata[[env]]64 4.735576 8.998145e-05 0.4936785
## logzdata[[env]]67 -4.427089 1.941579e-04 0.4600827
## logzdata[[env]]69 2.710422 1.248010e-02 0.2420844
## logzdata[[env]]70 4.575176 1.341968e-04 0.4764665
## logzdata[[env]]72 -2.415095 2.408191e-02 0.2022941
## logzdata[[env]]73 2.109717 4.597134e-02 0.1621406
## logzdata[[env]]80 2.151561 4.216783e-02 0.1675478
## logzdata[[env]]81 2.247855 3.447172e-02 0.1801190
## logzdata[[env]]84 2.687477 1.314700e-02 0.2389784
## logzdata[[env]]86 -2.552605 1.779546e-02 0.2207561
## logzdata[[env]]87 2.279915 3.220793e-02 0.1843396
## logzdata[[env]]90 6.234662 2.318897e-06 0.6282589
## logzdata[[env]]93 -2.705248 1.262762e-02 0.2413840
## logzdata[[env]]96 3.530886 1.788130e-03 0.3515127
## logzdata[[env]]104 2.984647 6.624687e-03 0.2791802
## logzdata[[env]]105 4.148743 3.886086e-04 0.4280325
## logzdata[[env]]106 2.197122 3.835116e-02 0.1734749
## logzdata[[env]]107 3.069361 5.427132e-03 0.2905828
## logzdata[[env]]108 3.499585 1.930010e-03 0.3474640
## logzdata[[env]]110 3.105547 4.981659e-03 0.2954386
## logzdata[[env]]111 -3.657699 1.310755e-03 0.3677630
## logzdata[[env]]112 -3.235889 3.651272e-03 0.3128376
## logzdata[[env]]113 3.988291 5.791367e-04 0.4088386
## logzdata[[env]]114 3.741731 1.065933e-03 0.3783876
## logzdata[[env]]115 3.463201 2.108793e-03 0.3427400
## logzdata[[env]]119 -3.219815 3.794549e-03 0.3107006
## logzdata[[env]]122 4.073837 4.682346e-04 0.4191355
## logzdata[[env]]124 -2.746973 1.148325e-02 0.2470338
## logzdata[[env]]125 -2.885637 8.345453e-03 0.2658068
## logzdata[[env]]126 -2.921962 7.669692e-03 0.2707179
## logzdata[[env]]128 -2.806781 1.001277e-02 0.2551335
## logzdata[[env]]143 -2.460795 2.179431e-02 0.2084118
## logzdata[[env]]144 2.556777 1.763110e-02 0.2213185
## logzdata[[env]]146 -2.485955 2.062251e-02 0.2117882
## logzdata[[env]]147 -2.487487 2.055308e-02 0.2119939
# Convert p-value to -log10 scale for better visualization
results_table$log_p_value <- -log10(results_table$p_value)
# Scatter plot
ggplot(results_table, aes(x = Coefficient, y = log_p_value, color = Response_Variable)) +
geom_point() +
facet_wrap(~Predictor_Variable, scales = "free") +
labs(
title = "Regression Coefficients vs. -log10(p-value)",
x = "Coefficient",
y = "-log10(p-value)",
color = "Response Variable"
) +
scale_x_continuous(labels = scales::number_format(accuracy = 0.1))
ggsave("scatterplot.png", width = 9, height = 6, units = "in")
#Remove other response variables from data set
a_zdata <- zdata[,-c(2:6)]
#*Train model*
#Set random number generator
set.seed(123)
#Set training and test set - 80% for training and 20% for test due to small data set
ind <- sample(2, nrow(a_zdata), replace = TRUE, prob = c(0.8, 0.2))
#Create training data frame
train <- a_zdata[ind==1]
#Create testing data frame
test <- a_zdata[ind==2,]
#Mean validation score
mean(en_a$resample$RMSE)
## [1] 0.6378428
#Plots
plot(en_a, main = "Elastic Net Regression - Allicin")
plot(varImp(en_a,scale=TRUE))
#Obtain coefficients
options(scipen=99)
coefs <- coef(en_a$finalModel,en_a$bestTune$lambda)
coefs.zero <- coefs[which(coefs==0),]
length(coefs.zero)
## [1] 7
# Rank order the predictors based on the magnitude of the coefficients
ind <- order(abs(coefs),decreasing=T)
# The first 10 predictors with the largest absolute coefficient (excluding the intercept)
head(as.matrix(coefs[ind,]),10)
## [,1]
## Slope -0.18802399
## Aspect 0.16819737
## S 0.12830510
## Fe 0.12824881
## PPFDROC -0.10028944
## Al 0.08467609
## PPFD3 0.08386826
## PPFD4 0.05832401
## N 0.03366103
## C 0.02103633
## Warning in rm(coefs, var_importance, var_coefs): object 'var_importance' not
## found
## Warning in rm(coefs, var_importance, var_coefs): object 'var_coefs' not found
#Mean validation score
mean(en_f$resample$RMSE)
## [1] 0.4363486
#Plots
plot(en_f, main = "Elastic Net Regression - Fresh Biomass")
plot(varImp(en_f,scale=TRUE))
#Obtain coefficients
options(scipen=99)
coefs <- coef(en_f$finalModel,en_f$bestTune$lambda)
coefs.zero <- coefs[which(coefs==0),]
length(coefs.zero)
## [1] 12
# Rank order the predictors based on the magnitude of the coefficients
ind <- order(abs(coefs),decreasing=T)
# The first 10 predictors with the largest absolute coefficient (excluding the intercept)
head(as.matrix(coefs[ind,]),10)
## [,1]
## TempMean -0.3553890517957313810449
## PPFD4 -0.3369390147357060882882
## WeeklyTempROC -0.3282369936684477185196
## Al -0.2469585794673070378025
## TempROC -0.0001027861751287968825
## Slope -0.0000769575950157651224
## (Intercept) -0.0000000000000007344024
## N 0.0000000000000000000000
## C 0.0000000000000000000000
## Mg 0.0000000000000000000000
## Warning in rm(coefs, var_importance, var_coefs): object 'var_importance' not
## found
## Warning in rm(coefs, var_importance, var_coefs): object 'var_coefs' not found
#Mean validation score
mean(en_d$resample$RMSE)
## [1] 0.4823345
#Plots
plot(en_d, main = "Elastic Net Regression - Dry Biomass")
plot(varImp(en_d,scale=TRUE))
#Obtain coefficients
options(scipen=99)
coefs <- coef(en_d$finalModel,en_d$bestTune$lambda)
coefs.zero <- coefs[which(coefs==0),]
length(coefs.zero)
## [1] 6
# Rank order the predictors based on the magnitude of the coefficients
ind <- order(abs(coefs),decreasing=T)
# The first 10 predictors with the largest absolute coefficient (excluding the intercept)
head(as.matrix(coefs[ind,]),10)
## [,1]
## Slope 0.32783256
## PPFD2 -0.21048624
## WeeklyTempROC 0.19060721
## N 0.15774754
## TempMean 0.11077504
## PPFD4 0.10217859
## PPFDROC -0.07951649
## C 0.06205896
## P 0.05268823
## TempROC 0.04296690
## Warning in rm(coefs, var_importance, var_coefs): object 'var_importance' not
## found
## Warning in rm(coefs, var_importance, var_coefs): object 'var_coefs' not found
#Mean validation score
mean(en_b$resample$RMSE)
## [1] 0.5009502
#Plots
plot(en_b, main = "Elastic Net Regression - Bulb Biomass")
plot(varImp(en_b,scale=TRUE))
#Obtain coefficients
options(scipen=99)
coefs <- coef(en_b$finalModel,en_b$bestTune$lambda)
coefs.zero <- coefs[which(coefs==0),]
length(coefs.zero)
## [1] 13
# Rank order the predictors based on the magnitude of the coefficients
ind <- order(abs(coefs),decreasing=T)
# The first 10 predictors with the largest absolute coefficient (excluding the intercept)
head(as.matrix(coefs[ind,]),10)
## [,1]
## Slope 0.6581927381943623034388
## PPFD2 -0.1861603845788756261825
## Fe -0.0882701372980989329431
## Mg 0.0299687114570114480905
## N 0.0109470556796699199781
## (Intercept) 0.0000000000000003676139
## C 0.0000000000000000000000
## K 0.0000000000000000000000
## Al 0.0000000000000000000000
## P 0.0000000000000000000000
## Warning in rm(coefs, var_importance, var_coefs): object 'var_importance' not
## found
## Warning in rm(coefs, var_importance, var_coefs): object 'var_coefs' not found
#Mean validation score
mean(en_bw$resample$RMSE)
## [1] 0.6320366
#Plots
plot(en_bw, main = "Elastic Net Regression - Bulb Width")
plot(varImp(en_bw,scale=TRUE))
#Obtain coefficients
options(scipen=99)
coefs <- coef(en_bw$finalModel,en_bw$bestTune$lambda)
coefs.zero <- coefs[which(coefs==0),]
length(coefs.zero)
## [1] 0
# Rank order the predictors based on the magnitude of the coefficients
ind <- order(abs(coefs),decreasing=T)
# The first 10 predictors with the largest absolute coefficient (excluding the intercept)
head(as.matrix(coefs[ind,]),10)
## [,1]
## Mg 0.13001819
## P 0.12861587
## Al -0.12157658
## Fe -0.11484187
## C 0.10931685
## WeeklyTempROC -0.10098296
## PPFD2 -0.09483397
## TempMean -0.09206807
## PPFD4 -0.08701797
## S 0.08461941
## Warning in rm(coefs, var_importance, var_coefs): object 'var_importance' not
## found
## Warning in rm(coefs, var_importance, var_coefs): object 'var_coefs' not found
#Mean validation score
mean(en_sla$resample$RMSE)
## [1] 0.875287
#Plots
plot(en_sla, main = "Elastic Net Regression - Specific Leaf Area")
plot(varImp(en_sla,scale=TRUE))
#Obtain coefficients
options(scipen=99)
coefs <- coef(en_sla$finalModel,en_sla$bestTune$lambda)
coefs.zero <- coefs[which(coefs==0),]
length(coefs.zero)
## [1] 17
# Rank order the predictors based on the magnitude of the coefficients
ind <- order(abs(coefs),decreasing=T)
# The first 10 predictors with the largest absolute coefficient (excluding the intercept)
head(as.matrix(coefs[ind,]),10)
## [,1]
## PPFD4 -0.28472418109904484850858
## (Intercept) 0.00000000000000002780367
## N 0.00000000000000000000000
## C 0.00000000000000000000000
## Mg 0.00000000000000000000000
## K 0.00000000000000000000000
## Al 0.00000000000000000000000
## Fe 0.00000000000000000000000
## P 0.00000000000000000000000
## S 0.00000000000000000000000
#Using standardized data
library(psych)
library(vegan)
library(adespatial)
## Warning: package 'adespatial' was built under R version 4.4.3
## Registered S3 methods overwritten by 'adegraphics':
## method from
## biplot.dudi ade4
## kplot.foucart ade4
## kplot.mcoa ade4
## kplot.mfa ade4
## kplot.pta ade4
## kplot.sepan ade4
## kplot.statis ade4
## scatter.coa ade4
## scatter.dudi ade4
## scatter.nipals ade4
## scatter.pco ade4
## score.acm ade4
## score.mix ade4
## score.pca ade4
## screeplot.dudi ade4
## Registered S3 methods overwritten by 'proxy':
## method from
## print.registry_field registry
## print.registry_entry registry
## Registered S3 method overwritten by 'spdep':
## method from
## plot.mst ape
## Registered S3 method overwritten by 'adespatial':
## method from
## plot.multispati adegraphics
NestedMatrix <- read.csv("Data/NestedMatrixCSV.csv")
#Omit Site names (not numeric)
original_data <- NestedMatrix[, -1]
zdata <- as.data.frame(scale(original_data))
#Select columns based on elastic net regression analysis
omit_columns <- c(1:7, 9:10, 12:13, 16, 21, 25:26, 29, 32)
env <- zdata[, -omit_columns]# Explanatory variables
rda_env <- as.data.frame(env)
rda_res <- zdata[, -c(7:32)]
pairs.panels(rda_env)
#Collinearity is still strong between several variables.
site_names<- c("CFUA", "RT", "PF", "CF", "SQAP")
rda_env$Site <- rep(site_names, each = 5)
rda_env1 <- rda_env[, !names(rda_env) %in% "Site", drop = FALSE]
rda_result <- rda(rda_res ~ PPFDROC + Slope + TempMean + PPFD4 + S + Al + Aspect + Mg + P + Fe + C + PPFD2 + PPFD3 + TempMin + WeeklyTempROC, data = rda_env1, grouping = rda_env$Site)
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'S', 'Al',
## 'Aspect', 'Mg', 'P', 'Fe', 'C', 'PPFD2', 'PPFD3', 'TempMin', 'WeeklyTempROC'
summary(rda_result)
##
## Call:
## rda(formula = rda_res ~ PPFDROC + Slope + TempMean + PPFD4 + S + Al + Aspect + Mg + P + Fe + C + PPFD2 + PPFD3 + TempMin + WeeklyTempROC, data = rda_env1, grouping = rda_env$Site)
##
## Partitioning of variance:
## Inertia Proportion
## Total 6.000 1.0000
## Constrained 4.043 0.6738
## Unconstrained 1.957 0.3262
##
## Eigenvalues, and their contribution to the variance
##
## Importance of components:
## RDA1 RDA2 RDA3 RDA4 PC1 PC2 PC3 PC4
## Eigenvalue 1.6589 1.5369 0.8408 0.00582 1.0572 0.4536 0.3072 0.08627
## Proportion Explained 0.2765 0.2562 0.1401 0.00097 0.1762 0.0756 0.0512 0.01438
## Cumulative Proportion 0.2765 0.5326 0.6728 0.67375 0.8500 0.9256 0.9768 0.99114
## PC5 PC6
## Eigenvalue 0.043231 0.009934
## Proportion Explained 0.007205 0.001656
## Cumulative Proportion 0.998344 1.000000
##
## Accumulated constrained eigenvalues
## Importance of components:
## RDA1 RDA2 RDA3 RDA4
## Eigenvalue 1.6589 1.5369 0.8408 0.00582
## Proportion Explained 0.4104 0.3802 0.2080 0.00144
## Cumulative Proportion 0.4104 0.7906 0.9986 1.00000
sqrt(vif.cca(rda_result))
## PPFDROC Slope TempMean PPFD4 S
## 1.751286 1.413839 1.816629 1.402437 NA
## Al Aspect Mg P Fe
## NA NA NA NA NA
## C PPFD2 PPFD3 TempMin WeeklyTempROC
## NA NA NA NA NA
anova.cca(rda_result)#global RDA significance
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = rda_res ~ PPFDROC + Slope + TempMean + PPFD4 + S + Al + Aspect + Mg + P + Fe + C + PPFD2 + PPFD3 + TempMin + WeeklyTempROC, data = rda_env1, grouping = rda_env$Site)
## Df Variance F Pr(>F)
## Model 4 4.0425 10.326 0.001 ***
## Residual 20 1.9575
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova.cca(rda_result, by = "axis") # significance of axes
## Permutation test for rda under reduced model
## Forward tests for axes
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = rda_res ~ PPFDROC + Slope + TempMean + PPFD4 + S + Al + Aspect + Mg + P + Fe + C + PPFD2 + PPFD3 + TempMin + WeeklyTempROC, data = rda_env1, grouping = rda_env$Site)
## Df Variance F Pr(>F)
## RDA1 1 1.65893 16.9498 0.001 ***
## RDA2 1 1.53694 15.7034 0.001 ***
## RDA3 1 0.84083 8.5910 0.001 ***
## RDA4 1 0.00582 0.0595 0.991
## Residual 20 1.95747
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova.cca(rda_result, by = "terms") #significance of terms
## Permutation test for rda under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = rda_res ~ PPFDROC + Slope + TempMean + PPFD4 + S + Al + Aspect + Mg + P + Fe + C + PPFD2 + PPFD3 + TempMin + WeeklyTempROC, data = rda_env1, grouping = rda_env$Site)
## Df Variance F Pr(>F)
## PPFDROC 1 0.93883 9.5923 0.001 ***
## Slope 1 1.55160 15.8531 0.001 ***
## TempMean 1 0.99155 10.1310 0.001 ***
## PPFD4 1 0.56054 5.7272 0.001 ***
## Residual 20 1.95747
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Trying forward selection with stopping criterion of R^2 value
R2 <- RsquareAdj(rda_result)
forward.sel(rda_res, rda_env1, adjR2thresh = R2)
## Testing variable 1
## Testing variable 2
## Testing variable 3
## Testing variable 4
## Procedure stopped (alpha criteria): pvalue for variable 4 is 0.177000 (> 0.050000)
## variables order R2 R2Cum AdjR2Cum F pvalue
## 1 Slope 7 0.2517277 0.2517277 0.2191941 7.737473 0.001
## 2 PPFD4 11 0.2069176 0.4586453 0.4094312 8.408882 0.001
## 3 C 1 0.1880873 0.6467326 0.5962659 11.180862 0.001
#Trying ordistep() which uses p-value as a stopping criterion
step.forward <- ordistep(rda(rda_res ~ 1, data=rda_env1), scope=formula(rda_result), direction="forward", pstep=1000)
##
## Start: rda_res ~ 1
##
## Df AIC F Pr(>F)
## + Slope 1 40.524 7.7375 0.005 **
## + PPFD4 1 42.120 5.8357 0.005 **
## + PPFD2 1 42.648 5.2333 0.005 **
## + WeeklyTempROC 1 42.801 5.0614 0.005 **
## + Al 1 42.921 4.9272 0.005 **
## + Fe 1 43.152 4.6696 0.005 **
## + C 1 43.170 4.6504 0.005 **
## + P 1 43.347 4.4555 0.005 **
## + TempMean 1 43.447 4.3458 0.005 **
## + PPFDROC 1 43.519 4.2664 0.005 **
## + S 1 43.609 4.1685 0.005 **
## + PPFD3 1 43.885 3.8706 0.010 **
## + Mg 1 43.914 3.8394 0.015 *
## + Aspect 1 44.694 3.0146 0.015 *
## + TempMin 1 46.866 0.8504 0.510
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: rda_res ~ Slope
##
## Df AIC F Pr(>F)
## + PPFD4 1 34.431 8.4089 0.005 **
## + WeeklyTempROC 1 35.842 6.7405 0.005 **
## + Al 1 36.029 6.5269 0.005 **
## + C 1 36.140 6.4000 0.005 **
## + S 1 36.320 6.1961 0.005 **
## + PPFDROC 1 36.367 6.1437 0.005 **
## + Fe 1 36.590 5.8930 0.005 **
## + TempMean 1 36.626 5.8532 0.005 **
## + PPFD3 1 37.105 5.3248 0.005 **
## + PPFD2 1 37.248 5.1687 0.005 **
## + Mg 1 37.400 5.0041 0.005 **
## + P 1 38.167 4.1882 0.010 **
## + Aspect 1 38.291 4.0587 0.010 **
## + TempMin 1 42.002 0.4644 0.765
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: rda_res ~ Slope + PPFD4
##
## Df AIC F Pr(>F)
## + C 1 25.760 11.1809 0.005 **
## + PPFDROC 1 25.952 10.9343 0.005 **
## + S 1 26.734 9.9510 0.005 **
## + Aspect 1 28.611 7.7129 0.005 **
## + TempMean 1 28.647 7.6712 0.005 **
## + WeeklyTempROC 1 28.678 7.6362 0.005 **
## + PPFD2 1 29.141 7.1104 0.005 **
## + Mg 1 30.470 5.6549 0.015 *
## + P 1 30.608 5.5087 0.015 *
## + Al 1 33.147 2.9483 0.040 *
## + Fe 1 33.541 2.5741 0.065 .
## + PPFD3 1 34.622 1.5767 0.195
## + TempMin 1 34.947 1.2844 0.265
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Step: rda_res ~ Slope + PPFD4 + C
##
## Df AIC F Pr(>F)
## + Mg 1 25.771 1.6565 0.140
## + PPFD3 1 25.771 1.6565 0.145
## + PPFDROC 1 25.771 1.6565 0.145
## + TempMin 1 25.771 1.6565 0.150
## + Aspect 1 25.771 1.6565 0.155
## + Fe 1 25.771 1.6565 0.155
## + Al 1 25.771 1.6565 0.170
## + S 1 25.771 1.6565 0.175
## + PPFD2 1 25.771 1.6565 0.175
## + P 1 25.771 1.6565 0.180
## + WeeklyTempROC 1 25.771 1.6565 0.190
## + TempMean 1 25.771 1.6565 0.220
#Results of forward selection indicate that C, PPFD4, and Slope are the most parsimonious contributors.Considering that forward selection does overfit data, the results are ecologically logical as they each represent a category of interacting environmental abiotic factors. The only category missing is temperature effect. When analyzing all prior tests, the temperature variable that explains the most variance is WeeklyTempROC. Rerun RDA with just these four variables.
rda_res <- zdata[, -c(5,7:32)]
rda_result <- rda(rda_res ~ WeeklyTempROC + C + PPFD4 + Slope, data = rda_env1, grouping = rda_env$Site)
summary(rda_result)
##
## Call:
## rda(formula = rda_res ~ WeeklyTempROC + C + PPFD4 + Slope, data = rda_env1, grouping = rda_env$Site)
##
## Partitioning of variance:
## Inertia Proportion
## Total 5.000 1.000
## Constrained 3.325 0.665
## Unconstrained 1.675 0.335
##
## Eigenvalues, and their contribution to the variance
##
## Importance of components:
## RDA1 RDA2 RDA3 RDA4 PC1 PC2 PC3
## Eigenvalue 1.6263 1.1964 0.49821 0.0042429 0.9071 0.40342 0.25288
## Proportion Explained 0.3253 0.2393 0.09964 0.0008486 0.1814 0.08068 0.05058
## Cumulative Proportion 0.3253 0.5645 0.66419 0.6650396 0.8465 0.92714 0.97771
## PC4 PC5
## Eigenvalue 0.08619 0.02525
## Proportion Explained 0.01724 0.00505
## Cumulative Proportion 0.99495 1.00000
##
## Accumulated constrained eigenvalues
## Importance of components:
## RDA1 RDA2 RDA3 RDA4
## Eigenvalue 1.6263 1.1964 0.4982 0.004243
## Proportion Explained 0.4891 0.3598 0.1498 0.001276
## Cumulative Proportion 0.4891 0.8489 0.9987 1.000000
sqrt(vif.cca(rda_result)) #check multicollinearity after selection
## WeeklyTempROC C PPFD4 Slope
## 3.751730 2.456980 3.123435 2.444459
anova.cca(rda_result)#global RDA significance
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = rda_res ~ WeeklyTempROC + C + PPFD4 + Slope, data = rda_env1, grouping = rda_env$Site)
## Df Variance F Pr(>F)
## Model 4 3.3252 9.9271 0.001 ***
## Residual 20 1.6748
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova.cca(rda_result, by = "axis") # significance of axes
## Permutation test for rda under reduced model
## Forward tests for axes
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = rda_res ~ WeeklyTempROC + C + PPFD4 + Slope, data = rda_env1, grouping = rda_env$Site)
## Df Variance F Pr(>F)
## RDA1 1 1.62631 19.4209 0.001 ***
## RDA2 1 1.19644 14.2876 0.001 ***
## RDA3 1 0.49821 5.9495 0.004 **
## RDA4 1 0.00424 0.0507 0.997
## Residual 20 1.67480
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova.cca(rda_result, by = "terms") #significance of terms
## Permutation test for rda under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = rda_res ~ WeeklyTempROC + C + PPFD4 + Slope, data = rda_env1, grouping = rda_env$Site)
## Df Variance F Pr(>F)
## WeeklyTempROC 1 0.82625 9.8668 0.001 ***
## C 1 0.79948 9.5471 0.001 ***
## PPFD4 1 1.23202 14.7124 0.001 ***
## Slope 1 0.46746 5.5822 0.002 **
## Residual 20 1.67480
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(eigenvals(rda_result, model = "constrained"))
## Importance of components:
## RDA1 RDA2 RDA3 RDA4
## Eigenvalue 1.6263 1.1964 0.4982 0.004243
## Proportion Explained 0.4891 0.3598 0.1498 0.001276
## Cumulative Proportion 0.4891 0.8489 0.9987 1.000000
screeplot(rda_result)
site_colors <- c("CFUA" = "darkorange3", "RT" = "darkolivegreen4", "PF" = "slateblue3", "CF" = "gold3", "SQAP" = "darkcyan")
colors <- sapply(rda_env$Site, function(site) site_colors[site])# Vector of colors/site
plot(rda_result, scaling = 2, main = "RDA - Scaling = 2", type = "n") #Data is already z-standardized, so default scaling is used. Scaling 2 displays effects of explanatory variables
# Plot circles with different colors and labels based on the 'Site' column
text(rda_result, display="species", col="firebrick3", cex=1)
points(rda_result, display="sites", cex=1.3, pch=20, col=colors)
text(rda_result, scaling = 2, display="bp", col="darkblue", cex=1)
# Add a legend
legend("topright", legend = unique(rda_env$Site), col = site_colors, pch = 19, title = "Site")
plot(rda_result, scaling = 1, main = "RDA - Scaling = 1", type = "n") #Using scaling 1 to look at relationships between objects
# Plot circles with different colors and labels based on the 'Site' column
text(rda_result, display="species", col="firebrick3", cex=1)
points(rda_result, display="sites", cex=1.3, pch=20, col=colors)
text(rda_result, scaling = 1, display="bp", col="darkblue", cex=1)
# Add a legend
legend("topright", legend = unique(rda_env$Site), col = site_colors, pch = 19, title = "Site")
## Warning: collinearity detected in X1: mm = 12, m = 4
## Warning: collinearity detected in X2: mm = 7, m = 4
## Warning: collinearity detected in X3: mm = 5, m = 4
## Warning: collinearity detected in cbind(X1,X2): mm = 19, m = 4
## Warning: collinearity detected in cbind(X1,X3: mm = 17, m = 4
## Warning: collinearity detected in cbind(X1,X4): mm = 13, m = 4
## Warning: collinearity detected in cbind(X2,X3): mm = 12, m = 4
## Warning: collinearity detected in cbind(X2,X4): mm = 8, m = 4
## Warning: collinearity detected in cbind(X3,X4): mm = 6, m = 4
## Warning: collinearity detected in cbind(X1,X2,X3): mm = 24, m = 4
## Warning: collinearity detected in c(X1,X2,X4): mm = 20, m = 4
## Warning: collinearity detected in cbind(X1,X3,X4): mm = 18, m = 4
## Warning: collinearity detected in cbind(X2,X3,X4): mm = 13, m = 4
## Warning: collinearity detected in cbind(X1,X2,X3,X4): mm = 25, m = 4
## No. of explanatory tables: 4
## Total variation (SS): 72
## Variance: 3
## No. of observations: 25
##
## Partition table:
## Df R.square Adj.R.square Testable
## [aeghklno] = X1 4 0.56270 0.47524 TRUE
## [befiklmo] = X2 4 0.56270 0.47524 TRUE
## [cfgjlmno] = X3 4 0.56270 0.47524 TRUE
## [dhijkmno] = X4 1 0.23658 0.20339 TRUE
## [abefghiklmno] = X1+X2 4 0.56270 0.47524 TRUE
## [acefghjklmno] = X1+X3 4 0.56270 0.47524 TRUE
## [adeghijklmno] = X1+X4 4 0.56270 0.47524 TRUE
## [bcefgijklmno] = X2+X3 4 0.56270 0.47524 TRUE
## [bdefhijklmno] = X2+X4 4 0.56270 0.47524 TRUE
## [cdfghijklmno] = X3+X4 4 0.56270 0.47524 TRUE
## [abcefghijklmno] = X1+X2+X3 4 0.56270 0.47524 TRUE
## [abdefghijklmno] = X1+X2+X4 4 0.56270 0.47524 TRUE
## [acdefghijklmno] = X1+X3+X4 4 0.56270 0.47524 TRUE
## [bcdefghijklmno] = X2+X3+X4 4 0.56270 0.47524 TRUE
## [abcdefghijklmno] = All 4 0.56270 0.47524 TRUE
## Individual fractions
## [a] = X1 | X2+X3+X4 0 0.00000 TRUE
## [b] = X2 | X1+X3+X4 0 0.00000 TRUE
## [c] = X3 | X1+X2+X4 0 0.00000 TRUE
## [d] = X4 | X1+X2+X3 0 0.00000 TRUE
## [e] 0 0.00000 FALSE
## [f] 0 0.00000 FALSE
## [g] 0 0.00000 FALSE
## [h] 0 0.00000 FALSE
## [i] 0 0.00000 FALSE
## [j] 0 0.00000 FALSE
## [k] 0 0.00000 FALSE
## [l] 0 0.27185 FALSE
## [m] 0 0.00000 FALSE
## [n] 0 0.00000 FALSE
## [o] 0 0.20339 FALSE
## [p] = Residuals 0 0.52476 FALSE
## Controlling 2 tables X
## [ae] = X1 | X3+X4 0 0.00000 FALSE
## [ag] = X1 | X2+X4 0 0.00000 FALSE
## [ah] = X1 | X2+X3 0 0.00000 FALSE
## [be] = X2 | X3+X4 0 0.00000 FALSE
## [bf] = X2 | X1+X4 0 0.00000 FALSE
## [bi] = X2 | X1+X3 0 0.00000 FALSE
## [cf] = X3 | X1+X4 0 0.00000 FALSE
## [cg] = X3 | X2+X4 0 0.00000 FALSE
## [cj] = X3 | X1+X2 0 0.00000 FALSE
## [dh] = X4 | X2+X3 0 0.00000 FALSE
## [di] = X4 | X1+X3 0 0.00000 FALSE
## [dj] = X4 | X1+X2 0 0.00000 FALSE
## Controlling 1 table X
## [aghn] = X1 | X2 0 0.00000 FALSE
## [aehk] = X1 | X3 0 0.00000 FALSE
## [aegl] = X1 | X4 3 0.27185 TRUE
## [bfim] = X2 | X1 0 0.00000 FALSE
## [beik] = X2 | X3 0 0.00000 FALSE
## [befl] = X2 | X4 3 0.27185 TRUE
## [cfjm] = X3 | X1 0 0.00000 FALSE
## [cgjn] = X3 | X2 0 0.00000 FALSE
## [cfgl] = X3 | X4 3 0.27185 TRUE
## [dijm] = X4 | X1 0 0.00000 FALSE
## [dhjn] = X4 | X2 0 0.00000 FALSE
## [dhik] = X4 | X3 0 0.00000 FALSE
## ---
## Use function 'rda' to test significance of fractions of interest
## Warning: collinearity detected: redundant variable(s) between tables X1, X2
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X3
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X2, X3
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X2, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X2, X3
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X2, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X2, X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X2, X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'Mg', 'K',
## 'Ca', 'Al', 'Fe', 'Mn', 'P', 'S'
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.chem)
## Df Variance F Pr(>F)
## Model 4 1.6881 6.4337 0.001 ***
## Residual 20 1.3119
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'PPFD5',
## 'PPFD6', 'PPFDROC'
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.light)
## Df Variance F Pr(>F)
## Model 4 1.6881 6.4337 0.001 ***
## Residual 20 1.3119
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'TempROC'
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.temp)
## Df Variance F Pr(>F)
## Model 4 1.6881 6.4337 0.001 ***
## Residual 20 1.3119
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.topo)
## Df Variance F Pr(>F)
## Model 1 0.70974 7.1276 0.001 ***
## Residual 23 2.29026
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning: collinearity detected in X1: mm = 12, m = 4
## Warning: collinearity detected in X2: mm = 7, m = 4
## Warning: collinearity detected in X3: mm = 5, m = 4
## Warning: collinearity detected in cbind(X1,X2): mm = 19, m = 4
## Warning: collinearity detected in cbind(X1,X3: mm = 17, m = 4
## Warning: collinearity detected in cbind(X1,X4): mm = 13, m = 4
## Warning: collinearity detected in cbind(X2,X3): mm = 12, m = 4
## Warning: collinearity detected in cbind(X2,X4): mm = 8, m = 4
## Warning: collinearity detected in cbind(X3,X4): mm = 6, m = 4
## Warning: collinearity detected in cbind(X1,X2,X3): mm = 24, m = 4
## Warning: collinearity detected in c(X1,X2,X4): mm = 20, m = 4
## Warning: collinearity detected in cbind(X1,X3,X4): mm = 18, m = 4
## Warning: collinearity detected in cbind(X2,X3,X4): mm = 13, m = 4
## Warning: collinearity detected in cbind(X1,X2,X3,X4): mm = 25, m = 4
## No. of explanatory tables: 4
## Total variation (SS): 120
## Variance: 5
## No. of observations: 25
##
## Partition table:
## Df R.square Adj.R.square Testable
## [aeghklno] = X1 4 0.66504 0.59805 TRUE
## [befiklmo] = X2 4 0.66504 0.59805 TRUE
## [cfgjlmno] = X3 4 0.66504 0.59805 TRUE
## [dhijkmno] = X4 1 0.29765 0.26712 TRUE
## [abefghiklmno] = X1+X2 4 0.66504 0.59805 TRUE
## [acefghjklmno] = X1+X3 4 0.66504 0.59805 TRUE
## [adeghijklmno] = X1+X4 4 0.66504 0.59805 TRUE
## [bcefgijklmno] = X2+X3 4 0.66504 0.59805 TRUE
## [bdefhijklmno] = X2+X4 4 0.66504 0.59805 TRUE
## [cdfghijklmno] = X3+X4 4 0.66504 0.59805 TRUE
## [abcefghijklmno] = X1+X2+X3 4 0.66504 0.59805 TRUE
## [abdefghijklmno] = X1+X2+X4 4 0.66504 0.59805 TRUE
## [acdefghijklmno] = X1+X3+X4 4 0.66504 0.59805 TRUE
## [bcdefghijklmno] = X2+X3+X4 4 0.66504 0.59805 TRUE
## [abcdefghijklmno] = All 4 0.66504 0.59805 TRUE
## Individual fractions
## [a] = X1 | X2+X3+X4 0 0.00000 TRUE
## [b] = X2 | X1+X3+X4 0 0.00000 TRUE
## [c] = X3 | X1+X2+X4 0 0.00000 TRUE
## [d] = X4 | X1+X2+X3 0 0.00000 TRUE
## [e] 0 0.00000 FALSE
## [f] 0 0.00000 FALSE
## [g] 0 0.00000 FALSE
## [h] 0 0.00000 FALSE
## [i] 0 0.00000 FALSE
## [j] 0 0.00000 FALSE
## [k] 0 0.00000 FALSE
## [l] 0 0.33093 FALSE
## [m] 0 0.00000 FALSE
## [n] 0 0.00000 FALSE
## [o] 0 0.26712 FALSE
## [p] = Residuals 0 0.40195 FALSE
## Controlling 2 tables X
## [ae] = X1 | X3+X4 0 0.00000 FALSE
## [ag] = X1 | X2+X4 0 0.00000 FALSE
## [ah] = X1 | X2+X3 0 0.00000 FALSE
## [be] = X2 | X3+X4 0 0.00000 FALSE
## [bf] = X2 | X1+X4 0 0.00000 FALSE
## [bi] = X2 | X1+X3 0 0.00000 FALSE
## [cf] = X3 | X1+X4 0 0.00000 FALSE
## [cg] = X3 | X2+X4 0 0.00000 FALSE
## [cj] = X3 | X1+X2 0 0.00000 FALSE
## [dh] = X4 | X2+X3 0 0.00000 FALSE
## [di] = X4 | X1+X3 0 0.00000 FALSE
## [dj] = X4 | X1+X2 0 0.00000 FALSE
## Controlling 1 table X
## [aghn] = X1 | X2 0 0.00000 FALSE
## [aehk] = X1 | X3 0 0.00000 FALSE
## [aegl] = X1 | X4 3 0.33093 TRUE
## [bfim] = X2 | X1 0 0.00000 FALSE
## [beik] = X2 | X3 0 0.00000 FALSE
## [befl] = X2 | X4 3 0.33093 TRUE
## [cfjm] = X3 | X1 0 0.00000 FALSE
## [cgjn] = X3 | X2 0 0.00000 FALSE
## [cfgl] = X3 | X4 3 0.33093 TRUE
## [dijm] = X4 | X1 0 0.00000 FALSE
## [dhjn] = X4 | X2 0 0.00000 FALSE
## [dhik] = X4 | X3 0 0.00000 FALSE
## ---
## Use function 'rda' to test significance of fractions of interest
## Warning: collinearity detected: redundant variable(s) between tables X1, X2
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X3
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X2, X3
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X2, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X2, X3
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X2, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X2, X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
## Warning: collinearity detected: redundant variable(s) between tables X1, X2, X3, X4
## results are probably incorrect: remove redundant variable(s) and repeat the analysis
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'Mg', 'K',
## 'Ca', 'Al', 'Fe', 'Mn', 'P', 'S'
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.chem)
## Df Variance F Pr(>F)
## Model 4 3.3252 9.9271 0.001 ***
## Residual 20 1.6748
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'PPFD5',
## 'PPFD6', 'PPFDROC'
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.light)
## Df Variance F Pr(>F)
## Model 4 3.3252 9.9271 0.001 ***
## Residual 20 1.6748
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Some constraints or conditions were aliased because they were redundant. This
## can happen if terms are constant or linearly dependent (collinear): 'TempROC'
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.temp)
## Df Variance F Pr(>F)
## Model 4 3.3252 9.9271 0.001 ***
## Residual 20 1.6748
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = env.res, Y = env.topo)
## Df Variance F Pr(>F)
## Model 1 1.4883 9.7473 0.001 ***
## Residual 23 3.5117
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(readr)
library(indicspecies)
## Warning: package 'indicspecies' was built under R version 4.4.3
library(vegan)
library(knitr)
#Load data
herb_data <- read.csv("Data/herb_data.csv")
herb_data <- herb_data[,-29]
#define data and grouping vector
abund = herb_data[,2:ncol(herb_data)]
site = herb_data$Site
#Standard ISA(for determining the predictive values of species as indicators of site conditions - always positive)
inv = multipatt(abund, site, func = "IndVal.g", control = how(nperm=999))
summary(inv, alpha=0.05)
##
## Multilevel pattern analysis
## ---------------------------
##
## Association function: IndVal.g
## Significance level (alpha): 0.05
##
## Total number of species: 27
## Selected number of species: 7
## Number of species associated to 1 group: 5
## Number of species associated to 2 groups: 1
## Number of species associated to 3 groups: 1
## Number of species associated to 4 groups: 0
##
## List of species associated to each combination:
##
## Group CFUA #sps. 3
## stat p.value
## DC 1.000 0.001 ***
## CLAY 0.982 0.001 ***
## CAR 0.775 0.026 *
##
## Group PF #sps. 2
## stat p.value
## FA 0.894 0.003 **
## SOL 0.775 0.021 *
##
## Group CF+PF #sps. 1
## stat p.value
## TG 0.775 0.02 *
##
## Group PF+RT+SQAP #sps. 1
## stat p.value
## EA 0.894 0.003 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Dividing inv into specificity and fidelity values - exclusivity and faithfulness to group
summary(inv, indvalcomp = TRUE)
##
## Multilevel pattern analysis
## ---------------------------
##
## Association function: IndVal.g
## Significance level (alpha): 0.05
##
## Total number of species: 27
## Selected number of species: 7
## Number of species associated to 1 group: 5
## Number of species associated to 2 groups: 1
## Number of species associated to 3 groups: 1
## Number of species associated to 4 groups: 0
##
## List of species associated to each combination:
##
## Group CFUA #sps. 3
## A B stat p.value
## DC 1.0000 1.0000 1.000 0.001 ***
## CLAY 0.9649 1.0000 0.982 0.001 ***
## CAR 1.0000 0.6000 0.775 0.026 *
##
## Group PF #sps. 2
## A B stat p.value
## FA 1.0 0.8 0.894 0.003 **
## SOL 1.0 0.6 0.775 0.021 *
##
## Group CF+PF #sps. 1
## A B stat p.value
## TG 1.0 0.6 0.775 0.02 *
##
## Group PF+RT+SQAP #sps. 1
## A B stat p.value
## EA 1.0 0.8 0.894 0.003 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#all species indicator values, regardless of significance
inv$sign
## s.CF s.CFUA s.PF s.RT s.SQAP index stat p.value
## AT 1 1 1 1 1 31 1.0000000 NA
## TG 1 0 1 0 0 7 0.7745967 0.020
## TE 1 1 0 0 0 6 0.4472136 1.000
## EA 0 0 1 1 1 25 0.8944272 0.003
## MR 0 1 0 0 0 2 0.6324555 0.170
## SC 0 0 0 1 0 4 0.6324555 0.179
## CORD 0 1 0 0 0 2 0.4472136 1.000
## CLAY 0 1 0 0 0 2 0.9822995 0.001
## CT 0 1 0 0 0 2 0.6324555 0.173
## CAR 0 1 0 0 0 2 0.7745967 0.026
## DC 0 1 0 0 0 2 1.0000000 0.001
## PA 1 0 1 0 0 7 0.5477226 0.438
## CP 0 0 1 0 0 3 0.6324555 0.167
## PP 0 0 0 1 1 15 0.5477226 0.472
## PV 0 0 1 0 0 3 0.6324555 0.171
## AS 0 1 0 1 0 11 0.6988362 0.064
## PS 0 1 0 0 0 2 0.4472136 1.000
## FG 0 1 0 0 0 2 0.6324555 0.170
## SF 0 0 0 0 1 5 0.4472136 1.000
## NAB 0 0 0 0 1 5 0.6324555 0.161
## RO 0 0 1 0 0 3 0.4472136 1.000
## FA 0 0 1 0 0 3 0.8944272 0.003
## TO 0 0 1 0 0 3 0.4472136 1.000
## SOL 0 0 1 0 0 3 0.7745967 0.021
## MC 0 0 1 0 0 3 0.4472136 1.000
## OV 0 0 1 0 0 3 0.6324555 0.167
## TA 0 0 1 0 0 3 0.4472136 1.000
#Simper() function examines relative contributions to differences at each site via Bray-Curtis (dis)similarity
sim <- simper(abund, site)
summary(sim)
##
## Contrast: CFUA_RT
##
## average sd ratio ava avb cumsum p
## DC 0.13393 0.07683 1.74330 23.20000 0.00000 0.205 0.001 ***
## CAR 0.13145 0.14650 0.89730 23.20000 0.00000 0.406 0.001 ***
## AT 0.10586 0.07500 1.41140 46.20000 29.20000 0.568 0.960
## CT 0.08384 0.11070 0.75730 13.00000 0.00000 0.696 0.001 ***
## EA 0.08226 0.08212 1.00170 0.00000 14.40000 0.822 0.982
## CLAY 0.06249 0.05248 1.19080 11.00000 0.00000 0.918 0.001 ***
## AS 0.03576 0.04120 0.86810 2.60000 5.80000 0.973 0.060 .
## SC 0.00571 0.00730 0.78280 0.00000 1.00000 0.981 0.047 *
## MR 0.00450 0.00666 0.67600 0.80000 0.00000 0.988 0.001 ***
## FG 0.00227 0.00284 0.79820 0.40000 0.00000 0.992 0.001 ***
## PP 0.00222 0.00280 0.79370 0.00000 0.40000 0.995 0.059 .
## TE 0.00120 0.00244 0.48910 0.20000 0.00000 0.997 0.396
## CORD 0.00104 0.00212 0.48930 0.20000 0.00000 0.998 0.001 ***
## PS 0.00104 0.00212 0.48930 0.20000 0.00000 1.000 0.001 ***
## TG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SF 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## NAB 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## RO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SOL 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## OV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: CFUA_PF
##
## average sd ratio ava avb cumsum p
## EA 0.12617 0.14403 0.87600 0.00000 30.20000 0.198 0.944
## DC 0.10833 0.06362 1.70290 23.20000 0.00000 0.369 0.001 ***
## CAR 0.10675 0.11918 0.89570 23.20000 0.00000 0.537 0.003 **
## AT 0.08910 0.05995 1.48640 46.20000 48.00000 0.677 0.973
## CT 0.06639 0.08782 0.75600 13.00000 0.00000 0.781 0.009 **
## CLAY 0.05070 0.04318 1.17430 11.00000 0.00000 0.861 0.001 ***
## FA 0.01881 0.01239 1.51790 0.00000 4.00000 0.890 0.002 **
## TG 0.01274 0.00514 2.48120 0.00000 2.80000 0.910 0.270
## MC 0.01181 0.02417 0.48860 0.00000 3.00000 0.929 0.272
## AS 0.01164 0.01666 0.69840 2.60000 0.20000 0.947 0.515
## SOL 0.00555 0.00652 0.85010 0.00000 1.20000 0.956 0.016 *
## CP 0.00552 0.00732 0.75500 0.00000 1.20000 0.965 0.052 .
## MR 0.00366 0.00545 0.67110 0.80000 0.00000 0.970 0.016 *
## OV 0.00363 0.00523 0.69390 0.00000 0.80000 0.976 0.066 .
## PV 0.00362 0.00461 0.78510 0.00000 0.80000 0.982 0.050 *
## PA 0.00311 0.00427 0.72750 0.00000 0.60000 0.987 0.177
## RO 0.00204 0.00419 0.48770 0.00000 0.40000 0.990 0.273
## FG 0.00184 0.00233 0.79270 0.40000 0.00000 0.993 0.016 *
## TO 0.00102 0.00210 0.48770 0.00000 0.20000 0.994 0.258
## TE 0.00096 0.00198 0.48640 0.20000 0.00000 0.996 0.447
## TA 0.00087 0.00178 0.48830 0.00000 0.20000 0.997 0.253
## CORD 0.00086 0.00176 0.48700 0.20000 0.00000 0.999 0.059 .
## PS 0.00086 0.00176 0.48700 0.20000 0.00000 1.000 0.059 .
## SC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SF 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## NAB 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: CFUA_CF
##
## average sd ratio ava avb cumsum p
## AT 0.35220 0.09674 3.64000 46.20000 139.40000 0.541 0.004 **
## DC 0.08720 0.05065 1.72200 23.20000 0.00000 0.674 0.003 **
## CAR 0.08620 0.09502 0.90700 23.20000 0.00000 0.807 0.040 *
## CT 0.05240 0.06846 0.76600 13.00000 0.00000 0.887 0.089 .
## CLAY 0.04090 0.03462 1.18200 11.00000 0.00000 0.950 0.016 *
## TG 0.01010 0.02074 0.48800 0.00000 2.40000 0.966 0.382
## AS 0.00930 0.01395 0.66900 2.60000 0.00000 0.980 0.611
## TE 0.00550 0.00984 0.55800 0.20000 1.20000 0.988 0.199
## MR 0.00300 0.00439 0.67400 0.80000 0.00000 0.993 0.102
## PA 0.00170 0.00346 0.48800 0.00000 0.40000 0.996 0.578
## FG 0.00150 0.00187 0.79800 0.40000 0.00000 0.998 0.054 .
## CORD 0.00070 0.00144 0.48900 0.20000 0.00000 0.999 0.360
## PS 0.00070 0.00144 0.48900 0.20000 0.00000 1.000 0.360
## EA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SF 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## NAB 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## RO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SOL 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## OV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: CFUA_SQAP
##
## average sd ratio ava avb cumsum p
## EA 0.50250 0.07280 6.90300 0.00000 165.00000 0.617 0.001 ***
## DC 0.06990 0.04075 1.71600 23.20000 0.00000 0.703 0.038 *
## CAR 0.06930 0.07604 0.91200 23.20000 0.00000 0.788 0.153
## AT 0.06900 0.04092 1.68600 46.20000 37.80000 0.872 0.998
## CT 0.04150 0.05387 0.77000 13.00000 0.00000 0.923 0.196
## CLAY 0.03200 0.02784 1.15000 11.00000 0.40000 0.962 0.130
## NAB 0.01530 0.02662 0.57300 0.00000 5.00000 0.981 0.077 .
## AS 0.00760 0.01134 0.66700 2.60000 0.00000 0.990 0.690
## MR 0.00240 0.00354 0.67400 0.80000 0.00000 0.993 0.328
## SF 0.00180 0.00377 0.48900 0.00000 0.60000 0.996 0.290
## FG 0.00120 0.00150 0.79800 0.40000 0.00000 0.997 0.155
## TE 0.00060 0.00126 0.48900 0.20000 0.00000 0.998 0.651
## PP 0.00060 0.00126 0.48900 0.00000 0.20000 0.999 0.758
## CORD 0.00060 0.00117 0.48900 0.20000 0.00000 0.999 0.400
## PS 0.00060 0.00117 0.48900 0.20000 0.00000 1.000 0.400
## TG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## RO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SOL 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## OV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: RT_PF
##
## average sd ratio ava avb cumsum p
## EA 0.19784 0.15184 1.30300 14.40000 30.20000 0.379 0.768
## AT 0.17316 0.12399 1.39660 29.20000 48.00000 0.711 0.661
## AS 0.03998 0.05550 0.72040 5.80000 0.20000 0.788 0.012 *
## FA 0.02819 0.01929 1.46150 0.00000 4.00000 0.842 0.001 ***
## TG 0.01883 0.00702 2.68300 0.00000 2.80000 0.878 0.010 **
## MC 0.01627 0.03326 0.48920 0.00000 3.00000 0.909 0.001 ***
## SOL 0.00821 0.00933 0.88040 0.00000 1.20000 0.925 0.001 ***
## CP 0.00816 0.01064 0.76660 0.00000 1.20000 0.940 0.001 ***
## SC 0.00688 0.00886 0.77690 1.00000 0.00000 0.954 0.006 **
## PV 0.00534 0.00689 0.77510 0.00000 0.80000 0.964 0.001 ***
## OV 0.00533 0.00753 0.70720 0.00000 0.80000 0.974 0.001 ***
## PA 0.00486 0.00668 0.72710 0.00000 0.60000 0.983 0.004 **
## RO 0.00317 0.00649 0.48850 0.00000 0.40000 0.990 0.001 ***
## PP 0.00266 0.00339 0.78540 0.40000 0.00000 0.995 0.014 *
## TO 0.00158 0.00324 0.48850 0.00000 0.20000 0.998 0.001 ***
## TA 0.00125 0.00255 0.48900 0.00000 0.20000 1.000 0.001 ***
## TE 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CORD 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CLAY 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CT 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CAR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## DC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SF 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## NAB 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: RT_CF
##
## average sd ratio ava avb cumsum p
## AT 0.56250 0.09033 6.22800 29.20000 139.40000 0.809 0.001 ***
## EA 0.07270 0.07243 1.00400 14.40000 0.00000 0.913 0.988
## AS 0.02950 0.04053 0.72700 5.80000 0.00000 0.956 0.207
## TG 0.01430 0.02933 0.48900 0.00000 2.40000 0.976 0.165
## TE 0.00720 0.01466 0.48900 0.00000 1.20000 0.987 0.003 **
## SC 0.00500 0.00644 0.78400 1.00000 0.00000 0.994 0.095 .
## PA 0.00240 0.00489 0.48900 0.00000 0.40000 0.997 0.355
## PP 0.00200 0.00248 0.79600 0.40000 0.00000 1.000 0.113
## MR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CORD 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CLAY 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CT 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CAR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## DC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SF 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## NAB 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## RO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SOL 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## OV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: RT_SQAP
##
## average sd ratio ava avb cumsum p
## EA 0.58400 0.11286 5.17400 14.40000 165.00000 0.826 0.001 ***
## AT 0.07210 0.05167 1.39500 29.20000 37.80000 0.928 1.000
## AS 0.02210 0.03038 0.72700 5.80000 0.00000 0.960 0.398
## NAB 0.01940 0.03374 0.57500 0.00000 5.00000 0.987 0.001 ***
## SC 0.00380 0.00485 0.78200 1.00000 0.00000 0.992 0.181
## SF 0.00230 0.00480 0.49000 0.00000 0.60000 0.996 0.001 ***
## PP 0.00170 0.00193 0.86500 0.40000 0.20000 0.998 0.212
## CLAY 0.00140 0.00280 0.49000 0.00000 0.40000 1.000 0.916
## TG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TE 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CORD 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CT 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CAR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## DC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## RO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SOL 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## OV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: PF_CF
##
## average sd ratio ava avb cumsum p
## AT 0.37860 0.08841 4.28200 48.00000 139.40000 0.665 0.001 ***
## EA 0.11520 0.13151 0.87600 30.20000 0.00000 0.867 0.951
## TG 0.01790 0.01504 1.19100 2.80000 2.40000 0.898 0.020 *
## FA 0.01700 0.01104 1.53700 4.00000 0.00000 0.928 0.004 **
## MC 0.01080 0.02217 0.48900 3.00000 0.00000 0.947 0.382
## TE 0.00580 0.01186 0.48600 0.00000 1.20000 0.957 0.125
## SOL 0.00500 0.00593 0.84600 1.20000 0.00000 0.966 0.053 .
## CP 0.00500 0.00663 0.75400 1.20000 0.00000 0.975 0.107
## PA 0.00340 0.00399 0.86300 0.60000 0.40000 0.981 0.107
## OV 0.00330 0.00475 0.69200 0.80000 0.00000 0.987 0.126
## PV 0.00330 0.00415 0.78900 0.80000 0.00000 0.993 0.081 .
## RO 0.00180 0.00375 0.48900 0.40000 0.00000 0.996 0.363
## TO 0.00090 0.00187 0.48900 0.20000 0.00000 0.997 0.354
## TA 0.00080 0.00162 0.48900 0.20000 0.00000 0.999 0.355
## AS 0.00070 0.00148 0.48900 0.20000 0.00000 1.000 0.970
## MR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CORD 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CLAY 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CT 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CAR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## DC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SF 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## NAB 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: PF_SQAP
##
## average sd ratio ava avb cumsum p
## EA 0.45840 0.16544 2.77050 30.20000 165.00000 0.755 0.002 **
## AT 0.07820 0.06532 1.19760 48.00000 37.80000 0.884 0.991
## NAB 0.01670 0.02921 0.57230 0.00000 5.00000 0.912 0.014 *
## FA 0.01330 0.00847 1.56530 4.00000 0.00000 0.934 0.055 .
## TG 0.00910 0.00381 2.37830 2.80000 0.00000 0.949 0.407
## MC 0.00880 0.01792 0.48920 3.00000 0.00000 0.963 0.384
## SOL 0.00390 0.00471 0.83550 1.20000 0.00000 0.970 0.282
## CP 0.00390 0.00523 0.75010 1.20000 0.00000 0.976 0.230
## OV 0.00260 0.00376 0.68800 0.80000 0.00000 0.980 0.368
## PV 0.00260 0.00325 0.79250 0.80000 0.00000 0.985 0.173
## PA 0.00210 0.00292 0.73080 0.60000 0.00000 0.988 0.425
## SF 0.00200 0.00414 0.48810 0.00000 0.60000 0.991 0.080 .
## RO 0.00140 0.00288 0.48890 0.40000 0.00000 0.994 0.411
## CLAY 0.00120 0.00246 0.48840 0.00000 0.40000 0.996 0.929
## TO 0.00070 0.00144 0.48890 0.20000 0.00000 0.997 0.425
## PP 0.00070 0.00138 0.48810 0.00000 0.20000 0.998 0.681
## TA 0.00060 0.00129 0.48910 0.20000 0.00000 0.999 0.433
## AS 0.00060 0.00119 0.48920 0.20000 0.00000 1.000 0.971
## TE 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CORD 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CT 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CAR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## DC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Contrast: CF_SQAP
##
## average sd ratio ava avb cumsum p
## EA 0.47000 0.06595 7.12700 0.00000 165.00000 0.596 0.001 ***
## AT 0.28920 0.08862 3.26300 139.40000 37.80000 0.962 0.033 *
## NAB 0.01430 0.02489 0.57300 0.00000 5.00000 0.980 0.166
## TG 0.00740 0.01509 0.48900 2.40000 0.00000 0.990 0.476
## TE 0.00370 0.00754 0.48900 1.20000 0.00000 0.994 0.373
## SF 0.00170 0.00352 0.48900 0.00000 0.60000 0.996 0.368
## PA 0.00120 0.00251 0.48900 0.40000 0.00000 0.998 0.641
## CLAY 0.00100 0.00213 0.48900 0.00000 0.40000 0.999 0.944
## PP 0.00060 0.00117 0.48900 0.00000 0.20000 1.000 0.766
## MR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CORD 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CT 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CAR 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## DC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## CP 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## AS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## PS 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FG 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## RO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## FA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TO 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## SOL 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## MC 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## OV 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## TA 0.00000 0.00000 NaN 0.00000 0.00000 1.000 NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Permutation: free
## Number of permutations: 999
#Correlation indices (for determining the ecological preferences of species - positive and negative)
herb_datapa <- ifelse(herb_data>0,1,0)
phi <- multipatt(herb_datapa,site, func = "r.g", control = how(nperm = 999))
summary(phi)
##
## Multilevel pattern analysis
## ---------------------------
##
## Association function: r.g
## Significance level (alpha): 0.05
##
## Total number of species: 28
## Selected number of species: 7
## Number of species associated to 1 group: 6
## Number of species associated to 2 groups: 0
## Number of species associated to 3 groups: 1
## Number of species associated to 4 groups: 0
##
## List of species associated to each combination:
##
## Group CFUA #sps. 3
## stat p.value
## DC 1.000 0.001 ***
## CLAY 0.890 0.001 ***
## CAR 0.739 0.027 *
##
## Group PF #sps. 3
## stat p.value
## TG 0.890 0.001 ***
## FA 0.873 0.001 ***
## SOL 0.739 0.020 *
##
## Group PF+RT+SQAP #sps. 1
## stat p.value
## EA 0.784 0.003 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
round(phi$str, 3)
## CF CFUA PF RT SQAP CF+CFUA CF+PF CF+RT CF+SQAP CFUA+PF
## Site NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
## AT NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
## TG -0.047 -0.281 0.890 -0.281 -0.281 -0.268 0.688 -0.268 -0.268 0.497
## TE 0.221 0.221 -0.147 -0.147 -0.147 0.361 0.060 0.060 0.060 0.060
## EA -0.480 -0.480 0.120 0.320 0.520 -0.784 -0.294 -0.131 0.033 -0.294
## MR -0.147 0.590 -0.147 -0.147 -0.147 0.361 -0.241 -0.241 -0.241 0.361
## SC -0.147 -0.147 -0.147 0.590 -0.147 -0.241 -0.241 0.361 -0.241 -0.241
## CORD -0.102 0.408 -0.102 -0.102 -0.102 0.250 -0.167 -0.167 -0.167 0.250
## CLAY -0.281 0.890 -0.281 -0.281 -0.047 0.497 -0.459 -0.459 -0.268 0.497
## CT -0.147 0.590 -0.147 -0.147 -0.147 0.361 -0.241 -0.241 -0.241 0.361
## CAR -0.185 0.739 -0.185 -0.185 -0.185 0.452 -0.302 -0.302 -0.302 0.452
## DC -0.250 1.000 -0.250 -0.250 -0.250 0.612 -0.408 -0.408 -0.408 0.612
## PA 0.123 -0.185 0.431 -0.185 -0.185 -0.050 0.452 -0.050 -0.050 0.201
## CP -0.147 -0.147 0.590 -0.147 -0.147 -0.241 0.361 -0.241 -0.241 0.361
## PP -0.185 -0.185 -0.185 0.431 0.123 -0.302 -0.302 0.201 -0.050 -0.302
## PV -0.147 -0.147 0.590 -0.147 -0.147 -0.241 0.361 -0.241 -0.241 0.361
## AS -0.281 0.187 -0.047 0.421 -0.281 -0.076 -0.268 0.115 -0.459 0.115
## PS -0.102 0.408 -0.102 -0.102 -0.102 0.250 -0.167 -0.167 -0.167 0.250
## FG -0.147 0.590 -0.147 -0.147 -0.147 0.361 -0.241 -0.241 -0.241 0.361
## SF -0.102 -0.102 -0.102 -0.102 0.408 -0.167 -0.167 -0.167 0.250 -0.167
## NAB -0.147 -0.147 -0.147 -0.147 0.590 -0.241 -0.241 -0.241 0.361 -0.241
## RO -0.102 -0.102 0.408 -0.102 -0.102 -0.167 0.250 -0.167 -0.167 0.250
## FA -0.218 -0.218 0.873 -0.218 -0.218 -0.356 0.535 -0.356 -0.356 0.535
## TO -0.102 -0.102 0.408 -0.102 -0.102 -0.167 0.250 -0.167 -0.167 0.250
## SOL -0.185 -0.185 0.739 -0.185 -0.185 -0.302 0.452 -0.302 -0.302 0.452
## MC -0.102 -0.102 0.408 -0.102 -0.102 -0.167 0.250 -0.167 -0.167 0.250
## OV -0.147 -0.147 0.590 -0.147 -0.147 -0.241 0.361 -0.241 -0.241 0.361
## TA -0.102 -0.102 0.408 -0.102 -0.102 -0.167 0.250 -0.167 -0.167 0.250
## CFUA+RT CFUA+SQAP PF+RT PF+SQAP RT+SQAP CF+CFUA+PF CF+CFUA+RT
## Site NaN NaN NaN NaN NaN NaN NaN
## AT NaN NaN NaN NaN NaN NaN NaN
## TG -0.459 -0.459 0.497 0.497 -0.459 0.459 -0.497
## TE 0.060 0.060 -0.241 -0.241 -0.241 0.241 0.241
## EA -0.131 0.033 0.360 0.523 0.686 -0.686 -0.523
## MR 0.361 0.361 -0.241 -0.241 -0.241 0.241 0.241
## SC 0.361 -0.241 0.361 -0.241 0.361 -0.361 0.241
## CORD 0.250 0.250 -0.167 -0.167 -0.167 0.167 0.167
## CLAY 0.497 0.688 -0.459 -0.268 -0.268 0.268 0.268
## CT 0.361 0.361 -0.241 -0.241 -0.241 0.241 0.241
## CAR 0.452 0.452 -0.302 -0.302 -0.302 0.302 0.302
## DC 0.612 0.612 -0.408 -0.408 -0.408 0.408 0.408
## PA -0.302 -0.302 0.201 0.201 -0.302 0.302 -0.201
## CP -0.241 -0.241 0.361 0.361 -0.241 0.241 -0.361
## PP 0.201 -0.050 0.201 -0.050 0.452 -0.452 0.050
## PV -0.241 -0.241 0.361 0.361 -0.241 0.241 -0.361
## AS 0.497 -0.076 0.306 -0.268 0.115 -0.115 0.268
## PS 0.250 0.250 -0.167 -0.167 -0.167 0.167 0.167
## FG 0.361 0.361 -0.241 -0.241 -0.241 0.241 0.241
## SF -0.167 0.250 -0.167 0.250 0.250 -0.250 -0.250
## NAB -0.241 0.361 -0.241 0.361 0.361 -0.361 -0.361
## RO -0.167 -0.167 0.250 0.250 -0.167 0.167 -0.250
## FA -0.356 -0.356 0.535 0.535 -0.356 0.356 -0.535
## TO -0.167 -0.167 0.250 0.250 -0.167 0.167 -0.250
## SOL -0.302 -0.302 0.452 0.452 -0.302 0.302 -0.452
## MC -0.167 -0.167 0.250 0.250 -0.167 0.167 -0.250
## OV -0.241 -0.241 0.361 0.361 -0.241 0.241 -0.361
## TA -0.167 -0.167 0.250 0.250 -0.167 0.167 -0.250
## CF+CFUA+SQAP CF+PF+RT CF+PF+SQAP CF+RT+SQAP CFUA+PF+RT CFUA+PF+SQAP
## Site NaN NaN NaN NaN NaN NaN
## AT NaN NaN NaN NaN NaN NaN
## TG -0.497 0.459 0.459 -0.497 0.268 0.268
## TE 0.241 -0.060 -0.060 -0.060 -0.060 -0.060
## EA -0.360 -0.033 0.131 0.294 -0.033 0.131
## MR 0.241 -0.361 -0.361 -0.361 0.241 0.241
## SC -0.361 0.241 -0.361 0.241 0.241 -0.361
## CORD 0.167 -0.250 -0.250 -0.250 0.167 0.167
## CLAY 0.459 -0.688 -0.497 -0.497 0.268 0.459
## CT 0.241 -0.361 -0.361 -0.361 0.241 0.241
## CAR 0.302 -0.452 -0.452 -0.452 0.302 0.302
## DC 0.408 -0.612 -0.612 -0.612 0.408 0.408
## PA -0.201 0.302 0.302 -0.201 0.050 0.050
## CP -0.361 0.241 0.241 -0.361 0.241 0.241
## PP -0.201 0.050 -0.201 0.302 0.050 -0.201
## PV -0.361 0.241 0.241 -0.361 0.241 0.241
## AS -0.306 0.076 -0.497 -0.115 0.459 -0.115
## PS 0.167 -0.250 -0.250 -0.250 0.167 0.167
## FG 0.241 -0.361 -0.361 -0.361 0.241 0.241
## SF 0.167 -0.250 0.167 0.167 -0.250 0.167
## NAB 0.241 -0.361 0.241 0.241 -0.361 0.241
## RO -0.250 0.167 0.167 -0.250 0.167 0.167
## FA -0.535 0.356 0.356 -0.535 0.356 0.356
## TO -0.250 0.167 0.167 -0.250 0.167 0.167
## SOL -0.452 0.302 0.302 -0.452 0.302 0.302
## MC -0.250 0.167 0.167 -0.250 0.167 0.167
## OV -0.361 0.241 0.241 -0.361 0.241 0.241
## TA -0.250 0.167 0.167 -0.250 0.167 0.167
## CFUA+RT+SQAP PF+RT+SQAP CF+CFUA+PF+RT CF+CFUA+PF+SQAP CF+CFUA+RT+SQAP
## Site NaN NaN NaN NaN NaN
## AT NaN NaN NaN NaN NaN
## TG -0.688 0.268 0.281 0.281 -0.890
## TE -0.060 -0.361 0.147 0.147 0.147
## EA 0.294 0.784 -0.520 -0.320 -0.120
## MR 0.241 -0.361 0.147 0.147 0.147
## SC 0.241 0.241 0.147 -0.590 0.147
## CORD 0.167 -0.250 0.102 0.102 0.102
## CLAY 0.459 -0.497 0.047 0.281 0.281
## CT 0.241 -0.361 0.147 0.147 0.147
## CAR 0.302 -0.452 0.185 0.185 0.185
## DC 0.408 -0.612 0.250 0.250 0.250
## PA -0.452 0.050 0.185 0.185 -0.431
## CP -0.361 0.241 0.147 0.147 -0.590
## PP 0.302 0.302 -0.123 -0.431 0.185
## PV -0.361 0.241 0.147 0.147 -0.590
## AS 0.268 0.076 0.281 -0.421 0.047
## PS 0.167 -0.250 0.102 0.102 0.102
## FG 0.241 -0.361 0.147 0.147 0.147
## SF 0.167 0.167 -0.408 0.102 0.102
## NAB 0.241 0.241 -0.590 0.147 0.147
## RO -0.250 0.167 0.102 0.102 -0.408
## FA -0.535 0.356 0.218 0.218 -0.873
## TO -0.250 0.167 0.102 0.102 -0.408
## SOL -0.452 0.302 0.185 0.185 -0.739
## MC -0.250 0.167 0.102 0.102 -0.408
## OV -0.361 0.241 0.147 0.147 -0.590
## TA -0.250 0.167 0.102 0.102 -0.408
## CF+PF+RT+SQAP CFUA+PF+RT+SQAP
## Site NaN NaN
## AT NaN NaN
## TG 0.281 0.047
## TE -0.221 -0.221
## EA 0.480 0.480
## MR -0.590 0.147
## SC 0.147 0.147
## CORD -0.408 0.102
## CLAY -0.890 0.281
## CT -0.590 0.147
## CAR -0.739 0.185
## DC -1.000 0.250
## PA 0.185 -0.123
## CP 0.147 0.147
## PP 0.185 0.185
## PV 0.147 0.147
## AS -0.187 0.281
## PS -0.408 0.102
## FG -0.590 0.147
## SF 0.102 0.102
## NAB 0.147 0.147
## RO 0.102 0.102
## FA 0.218 0.218
## TO 0.102 0.102
## SOL 0.185 0.185
## MC 0.102 0.102
## OV 0.147 0.147
## TA 0.102 0.102
#ISA across all sites
inv_inter <- multipatt(abund, site, duleg = TRUE, control = how(nperm=999))
summary(inv_inter)
##
## Multilevel pattern analysis
## ---------------------------
##
## Association function: IndVal.g
## Significance level (alpha): 0.05
##
## Total number of species: 27
## Selected number of species: 8
## Number of species associated to 1 group: 8
## Number of species associated to 2 groups: 0
## Number of species associated to 3 groups: 0
## Number of species associated to 4 groups: 0
##
## List of species associated to each combination:
##
## Group CF #sps. 1
## stat p.value
## AT 0.681 0.001 ***
##
## Group CFUA #sps. 3
## stat p.value
## DC 1.000 0.002 **
## CLAY 0.982 0.002 **
## CAR 0.775 0.028 *
##
## Group PF #sps. 3
## stat p.value
## FA 0.894 0.002 **
## SOL 0.775 0.015 *
## TG 0.734 0.016 *
##
## Group SQAP #sps. 1
## stat p.value
## EA 0.887 0.001 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(ade4)
library(vegan)
library(MASS)
library(ellipse)
## Warning: package 'ellipse' was built under R version 4.4.3
##
## Attaching package: 'ellipse'
## The following object is masked from 'package:car':
##
## ellipse
## The following object is masked from 'package:graphics':
##
## pairs
library(FactoMineR)
library(factoextra)
library(ggrepel)
herb_data <- read.csv("Data/herb_data.csv")
NestedMatrix_herb <- read.csv("Data/NestedMatrix_herbCSV.csv")
#Omit Site names (not numeric)
herb_data2 <- herb_data[, -1]
herb.hel <- decostand(herb_data2, "hellinger")
original_data <- NestedMatrix_herb[, -1]
zdata <- as.data.frame(scale(original_data))
#RDA of species with parsimonius environmnental variables across sites
rownames(herb.hel)<- NestedMatrix_herb$Site
herb.rda <- rda(herb.hel ~ WeeklyTempROC + C + PPFD4 + Slope, data = zdata)
sites_to_label <- c("CFUA", "RT", "PF", "CF", "SQAP")
plot(herb.rda, scaling=2, display = c("sp", "lc", "cn"), main="RDA Triplot - Understory Species Associations - scaling=2", xlab="RDA1", ylab="RDA2", xlim=c(-1, 1), ylim=c(-1,1))
for (site in sites_to_label) {
site_coords <- scores(herb.rda, display = "sites")[site, ]
text(site_coords["RDA1"], site_coords["RDA2"], labels = site, cex = 0.7, col = "darkgreen")
}
summary(herb.rda)
##
## Call:
## rda(formula = herb.hel ~ WeeklyTempROC + C + PPFD4 + Slope, data = zdata)
##
## Partitioning of variance:
## Inertia Proportion
## Total 0.3872 1.0000
## Constrained 0.2412 0.6229
## Unconstrained 0.1460 0.3771
##
## Eigenvalues, and their contribution to the variance
##
## Importance of components:
## RDA1 RDA2 RDA3 RDA4 PC1 PC2 PC3
## Eigenvalue 0.1502 0.0679 0.01547 0.007585 0.06067 0.03652 0.01346
## Proportion Explained 0.3879 0.1754 0.03997 0.019590 0.15671 0.09431 0.03476
## Cumulative Proportion 0.3879 0.5633 0.60328 0.622873 0.77958 0.87389 0.90865
## PC4 PC5 PC6 PC7 PC8 PC9
## Eigenvalue 0.006954 0.006214 0.005933 0.003687 0.003496 0.002831
## Proportion Explained 0.017959 0.016050 0.015324 0.009522 0.009029 0.007311
## Cumulative Proportion 0.926607 0.942657 0.957981 0.967504 0.976533 0.983843
## PC10 PC11 PC12 PC13 PC14 PC15
## Eigenvalue 0.002008 0.001840 0.0008418 0.0005847 0.0004341 0.0003594
## Proportion Explained 0.005187 0.004752 0.0021741 0.0015102 0.0011211 0.0009283
## Cumulative Proportion 0.989030 0.993783 0.9959568 0.9974671 0.9985882 0.9995165
## PC16 PC17
## Eigenvalue 0.0001866 0.0000005679
## Proportion Explained 0.0004821 0.0000014667
## Cumulative Proportion 0.9999985 1.0000000000
##
## Accumulated constrained eigenvalues
## Importance of components:
## RDA1 RDA2 RDA3 RDA4
## Eigenvalue 0.1502 0.0679 0.01547 0.007585
## Proportion Explained 0.6228 0.2816 0.06416 0.031451
## Cumulative Proportion 0.6228 0.9044 0.96855 1.000000