data("wellington_OTU_clean")
data("WRS_abiotic_model")
list2env(wellington_OTU_clean, envir = .GlobalEnv)
list2env(WRS_abiotic_model, envir = .GlobalEnv)
model_data <- cbind(elements, hydrogeo, nutrients, redox, water_qual)
fungi_RDA <- capscale(fungi ~ ., data = model_data, distance = "bray", scale = TRUE, add = TRUE)
plot(fungi_RDA, scaling = 2)
text(fungi_RDA, scaling = 2)
summary(fungi_RDA)

# Turns out there's too many terms for forward selection with ordiR2step.
fungi_step <- ordistep(fungi_null, scope = formula(fungi_RDA), direction = "both")


# Variation partitioning
# Can only do up to 4 explanatory matrices
water_chem <- cbind(hydrogeo[, c("water_table_start", "depth_pumped")], water_qual)
fungi_dist <- vegdist(fungi)
(fungi_varpart <- varpart(fungi_dist, water_chem, redox, nutrients, elements))
# Looks like elements are the most explanatory, and redox the least. But there is collinearity, as well as the issue of using so many variables (54) to observations (48). Might need to rethink the strategy here.


# How much could feature extraction & simplification help?
abiotic_PCA <- rda(model_data[, names(model_data) != "hydrogeol_cat"], scale = TRUE)
plot(abiotic_PCA)
summary(abiotic_PCA)
screeplot(abiotic_PCA, bstick = TRUE)
# Quite a lot - first two axes are very descriptive, though the next two are still maybe useful.


mixtrak/wellington.aquifer.ecol documentation built on Nov. 30, 2017, 4:25 a.m.