Depends on analysis_nonpublic.R
to load the raw dataset rawlui
and plotNAset
# Load requirements from <..>nonpublic.R file sections_to_be_loaded <- c("raw_lui") source("vignettes/analysis_nonpublic.R")
Years 2006 to 2016. We have information until 2017, but the range of functions is until 2016.
$$LUI = \frac{1}{11} \left( \sum_{i = 2006}^{2016} \sqrt{\frac{G_i}{mean(G_i)}+ \frac{M_i}{mean(M_i)} + \frac{F_i}{mean(F_i)}} \right)$$
code by Caterina Penone
luiy <- data.table::copy(rawlui) luiy <- luiy[Year != "2017", ] # calculate the global means luiy[,MeanF:=mean(TotalFertilization,na.rm = T)] luiy[,MeanM:=mean(TotalMowing,na.rm = T)] luiy[,MeanG:=mean(TotalGrazing,na.rm = T)] # calculate the LUI and its components for each year and each plot, using the global mean luiy[ , LUI := sqrt((TotalFertilization/MeanF) + (TotalMowing/MeanM) +(TotalGrazing / MeanG)), by=EP_PlotID] luiy[ ,Fstd := TotalFertilization / MeanF, by = EP_PlotID] luiy[ ,Mstd := TotalMowing / MeanM, by = EP_PlotID] luiy[ ,Gstd := TotalGrazing / MeanG , by = EP_PlotID] # calculate DELTA LUI and DELTA COMPONENTS luiy[ , deltaLUI := sd(LUI), by = EP_PlotID] luiy[ , deltaFstd := sd(Fstd), by = EP_PlotID] luiy[ , deltaMstd := sd(Mstd), by = EP_PlotID] luiy[ , deltaGstd := sd(Gstd), by = EP_PlotID] # clean and format luiy <- luiy[,.(EP_PlotID,LUI, Gstd, Mstd, Fstd, deltaLUI, deltaGstd, deltaMstd, deltaFstd)] data.table::setnames(luiy, old = "EP_PlotID", new = "Plot") luiy <- merge(luiy, usefulplotids, by = "Plot") luiy[, Plot := NULL] # calculate the means over 11 years lui <- aggregate(LUI~Plotn, luiy, mean) lui <- merge(lui, aggregate(Gstd~Plotn, luiy, mean), by = "Plotn") lui <- merge(lui, aggregate(Mstd ~ Plotn, luiy, mean), by = "Plotn") lui <- merge(lui, aggregate(Fstd ~ Plotn, luiy, mean), by = "Plotn") lui <- merge(lui, aggregate(deltaLUI ~ Plotn, luiy, mean), by = "Plotn") lui <- merge(lui, aggregate(deltaGstd ~ Plotn, luiy, mean), by = "Plotn") lui <- merge(lui, aggregate(deltaMstd ~ Plotn, luiy, mean), by = "Plotn") lui <- merge(lui, aggregate(deltaFstd ~ Plotn, luiy, mean), by = "Plotn")
Select set of plots
lui <- lui[which(lui$Plotn %in% plotNAset),]
Save for analysis
saveRDS(lui, "LUI.rds")
Prepare LUI euclidean distance
test <- as.matrix(lui[, .(LUI)]) rownames(test) <- lui$Plotn test <- vegan::vegdist(test, method = "euclid") test <- as.matrix(test) test[!lower.tri(test)] <- NA test <- reshape2::melt(test, value.name = "distLUI") test <- test[!is.na(test[, 3]),] test <- data.table::data.table(test) saveRDS(test, "distLUI.rds")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.