requires analysis_nonpublic.R to load soil covariates small_glsoil, main_glsoil, names_gl, plt.sur, geodist.

sections_to_be_loaded <- c("assemble_covariates")
source("vignettes/analysis_nonpublic.R")

Clean and load soil covariates

This scripts loads and cleans soil covariates (also selects the plots for analysis). The output is then used (by other scripts) for - preparation for soil covariates for analysis

Soil

Cleaning soil covariates

small_glsoil <- small_glsoil[, c("Plot", "Soil.type", "TWI")]
# take out empty row at the end
small_glsoil <- small_glsoil[Plot != "",]

clean and merge covariate dataset

plot.names <- names_gl[Landuse == "G",.(EP_PlotID,PlotID)]
data.table::setnames(plot.names, old="EP_PlotID", new="Plot")
# add useful plot IDs
plot.names <- merge(plot.names, usefulplotids, by="Plot", all=T)
# merge main_glsoil with plot.names to get the wanted names
data.table::setnames(main_glsoil, "plotid","PlotID")
main_glsoil <- merge(main_glsoil, plot.names, by="PlotID", all=T)
# main_glsoil[Plotn %in% c("AEG29", "AEG10"),] # there are two duplicated rows without data
main_glsoil <- main_glsoil[!PlotID %in% c("A32886", "A8338"),]

# merge the 2 datasets
data.table::setnames(small_glsoil, "Plot", "Plotn")
glsoil <- merge(main_glsoil, small_glsoil, by="Plotn", all=T)
rm(main_glsoil) ; rm(plot.names) ; rm(small_glsoil)

# remove unwanted columns
glsoil[, c("PlotID", "Exploratory", "Plot") := NULL]

Plot selection

# take out the plots that I exclude from analysis
glsoil <- glsoil[Plotn %in% plotNAset ,]

Create binary data from Soil.type

Because PCA can not fit categorical data which have > 2 categories. This probably adds some overlapping information with the amount of sand, clay etc. But this does not matter, as selecting the PCA components will take this extra information out again.

stype <- glsoil[, .(Plotn, Soil.type)]
stype[, Rendzina := ifelse(Soil.type == "Rendzina", 1, 0)]
stype[, Braunerde := ifelse(Soil.type == "Braunerde", 1, 0)]
stype[, Pelosol := ifelse(Soil.type == "Pelosol", 1, 0)]
stype[, Pseudogley := ifelse(Soil.type == "Pseudogley", 1, 0)]
stype[, Erdniedermoor := ifelse(Soil.type == "Erdniedermoor", 1, 0)]
stype[, Gley := ifelse(Soil.type == "Gley", 1, 0)]
stype[, Mulmniedermoor := ifelse(Soil.type == "Mulmniedermoor", 1, 0)]
stype[, Parabraunerde := ifelse(Soil.type == "Parabraunerde", 1, 0)]
stype[, Fahlerde := ifelse(Soil.type == "Fahlerde", 1, 0)]
stype[, Soil.type := NULL]
# merge to glsoil
glsoil <- merge(glsoil, stype, by="Plotn", all=T)
rm(stype)
fwrite(glsoil, "vignettes/out/intermediate_glsoil.csv") # saved in data_assembly/output_data/


allanecology/BetaDivMultifun documentation built on Nov. 9, 2023, 8:47 p.m.