library(dplyr)
### Use the entire of 209 plots data from six countries
# \donttest{
## within-ecosystem MF computation
data("forest_function_data_normalized")
data("forest_biodiversity_data")
output1 <- MF1_single(func_data = forest_function_data_normalized[,6:31], weight = 1,
species_data = forest_biodiversity_data)
## BEF relationships: display fitted line of linear mixed model with random slopes and
## random intercepts
output1 <- data.frame(output1, country=rep(forest_function_data_normalized$country, each = 6))
MFggplot(output1, model = "LMM.both", by_group="country", caption = "slope")
### Use partial data to quickly obtain output
### (Take the first 18 plots in Germany and the last 18 plots in Italy)
## within-ecosystem MF computation for partial data
data("forest_function_data_raw")
data("forest_biodiversity_data")
GER_ITA_forest_function_raw <- filter(forest_function_data_raw,
country=="GER"|country=="ITA")[c(1:18,57:74),]
GER_ITA_forest_function_normalized <- function_normalization(data = GER_ITA_forest_function_raw,
fun_cols = 6:31,
negative = c("soil_cn_ff_10","wue"),
by_group = "country")
GER_ITA_forest_biodiversity <- forest_biodiversity_data[c(49:82,181:229),]
output2 <- MF1_single(func_data = GER_ITA_forest_function_normalized[,6:31], weight = 1,
species_data = GER_ITA_forest_biodiversity)
## BEF relationships: display fitted line of linear mixed model with random slopes and
## random intercepts
output2 <- data.frame(output2, country=rep(GER_ITA_forest_function_normalized$country, each = 6))
MFggplot(output2, model = "LMM.both", by_group="country", caption = "slope")
### Use data from plots in five countries (data in Finland are excluded)
## MF decomposition for all pairs of ecosystems
data("forest_function_data_normalized")
data("forest_biodiversity_data")
forest_function_data_normalized <- filter(forest_function_data_normalized, country != "FIN")
forest_biodiversity_data <- forest_biodiversity_data[-(1:48),]
output3 <- MF2_multiple(func_data = forest_function_data_normalized[,6:32],
species_data = forest_biodiversity_data,
weight = 1,
by_group = "country")
## BEF relationships: display fitted line of linear mixed model with random slopes and
## random intercepts
figure_LMM <- MFggplot(output3, model = "LMM.both", by_group = "country",
caption = "slope")
figure_LMM$corr_uncorrected$ALL
figure_LMM$corr_corrected$ALL
# }
# \donttest{
### Use partial data to quickly obtain output
### (Take the first 18 plots in Germany and the last 18 plots in Italy)
## MF decomposition for all pairs of ecosystems for partial data
data("forest_function_data_raw")
data("forest_biodiversity_data")
GER_ITA_forest_function_raw <- filter(forest_function_data_raw,
country=="GER"|country=="ITA")[c(1:18,57:74),]
GER_ITA_forest_function_normalized <- function_normalization(data = GER_ITA_forest_function_raw,
fun_cols = 6:31,
negative = c("soil_cn_ff_10","wue"),
by_group = "country")
GER_ITA_forest_biodiversity <- forest_biodiversity_data[c(49:82,181:229),]
output4 <- MF2_multiple(func_data = GER_ITA_forest_function_normalized[,6:32],
species_data = GER_ITA_forest_biodiversity,
weight = 1,
by_group = "country")
## BEF relationships: display fitted line of linear mixed model with random slopes and
## random intercepts for partial data
figure_LMM_GER_ITA <- MFggplot(output4, model = "LMM.both", by_group = "country",
caption = "slope")
figure_LMM_GER_ITA$corr_uncorrected$ALL
figure_LMM_GER_ITA$corr_corrected$ALL
# }
### Use partial data to calculate multifunctionality based on 3 plots in each country, not by pairs
### (Take the first 3 plots in each country)
data("forest_function_data_raw")
data("forest_biodiversity_data")
forest_function_data_raw_3plots <- forest_function_data_raw[c(1:3,29:31,67:69,103:105,
146:148,174:176),]
forest_function_data_normalized_3plots <-
function_normalization(data = forest_function_data_raw_3plots,
fun_cols = 6:31,
negative = c("soil_cn_ff_10","wue"),
by_group = "country")
forest_biodiversity_data_3plots <-
forest_biodiversity_data[c(1:6,49:52,141:148,230:232,351:355,411:417),]
output5 <- MF2_multiple(func_data = forest_function_data_normalized_3plots[,6:32],
species_data = forest_biodiversity_data_3plots,
weight = 1,
by_group = "country", by_pair = FALSE)
## BEF relationships: display fitted line of linear model
figure_all_plots <- MFggplot(output5, model = "lm", caption = "slope")
figure_all_plots$corr_uncorrected$ALL
figure_all_plots$corr_corrected$ALL
Run the code above in your browser using DataLab