####################################################################################################
### Code to generate a table that summarizes the output of linear mixed effects models
### used to identify drivers of bubble size distributions and turbulence in mountain streams
####################################################################################################

# Creates Table S6 in
# Klaus, M., Durighetto, N., Khan, A. M., Chatton, E., Öquist, M., Peruzzo, P. and Botter, G. (in revision in "npj Hydrosphere").
# Bubble size spectra reveal distinct scaling patterns and downstream sorting in mountain streams 

###########################################################################################
## created by Marcus Klaus, Swedish University of Agricultural Sciences (SLU), Umeå, Sweden
## contact: marcus.klaus@slu.se
## last update: 2026/08/11
###########################################################################################

## load libraries
library(r2glmm)
library(MuMIn)



TableS6 <- data.frame(summary(modalphaABS50s_mod)$coefficients$fixed,intervals(modalphaABS50s_mod)$fixed[,c(1,3)],r.squaredGLMM(modalphaABS50s_mod)[1],r.squaredGLMM(modalphaABS50s_mod)[2])




TableS6$predictor <- gsub("[0-9]", "", rownames(TableS6))
rownames(TableS6) <- NULL

TableS6 <- data.frame(TableS6$predictor,TableS6[,-grep("predictor",names(TableS6))])
names(TableS6)[1] <- "predictor"

TableS6$predictor <- gsub("x","alpha50_measured",TableS6$predictor)


TableS6$predicted <- c("alpha50_modelled","")
TableS6 <- data.frame(TableS6[7],TableS6[1:6])


colnames(TableS6) <- c("Predicted","Predictor","Estimate","Lower 95% CI bound","Upper 95% CI bound","R2m","R2c")

print(TableS6)






