tutorials:sensitivity-analysis-using-grolink-and-gror
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:sensitivity-analysis-using-grolink-and-gror [2024/06/25 15:29] – [Model execution and output gathering in R] thomas | tutorials:sensitivity-analysis-using-grolink-and-gror [2024/07/01 12:39] (current) – [Example: Morris Screening using the sensitivity package] thomas | ||
---|---|---|---|
Line 3: | Line 3: | ||
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Make sure to [[: | Make sure to [[: | ||
+ | |||
+ | ==== Downloads ==== | ||
+ | * {{ : | ||
+ | * {{ : | ||
===== Prepare your model===== | ===== Prepare your model===== | ||
Line 105: | Line 109: | ||
</ | </ | ||
- | Now here is the function | + | Now here is the code that gets the model output. It executes the '' |
<code R> | <code R> | ||
Line 126: | Line 130: | ||
===== Example: Morris Screening using the sensitivity package ===== | ===== Example: Morris Screening using the sensitivity package ===== | ||
+ | The Morris Screening will be used to analyze the 5 structural plant growth parameters with regard to their importance (their main and interaction effect) on the total amount of absorbed light by leaves. This is just a random example out of the plethora of available sensitivity analysis methods. Most of the common ones are implemented in the '' | ||
+ | |||
+ | First, I generate a set of input parameters for the model: | ||
+ | |||
+ | <code R> | ||
+ | m <- morris(model = NULL, factors = c(" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | r = 20, # 20 repetitions | ||
+ | binf = c(0.05, 0.01, 0.05, 0.1, 0.1), # min value of inputs | ||
+ | bsup = c(0.8, 0.1, 1, 1, 1), # max value of inputs | ||
+ | | ||
+ | # grid.jump is recommended to be levels/2, see ?morris | ||
+ | |||
+ | |||
+ | params <- m$X | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code R> | ||
+ | executeModel <- function(params, | ||
+ | wb1 <- GroLink.open(" | ||
+ | WBRef.updateFile(wb1, | ||
+ | | ||
+ | "; | ||
+ | "; | ||
+ | "; | ||
+ | "; | ||
+ | ";", | ||
+ | sep = "" | ||
+ | |||
+ | WBRef.compile(wb1) | ||
+ | |||
+ | model_output <- "" | ||
+ | n_grows <- 0 | ||
+ | while (!(is.numeric(model_output)) && (n_grows < timeout)) { | ||
+ | result <- WBRef.runRGGFunction(wb1," | ||
+ | model_output <- unlist(result$console) | ||
+ | if (model_output != "no flower" | ||
+ | model_output <- as.numeric(model_output) | ||
+ | } | ||
+ | n_grows <- n_grows + 1 | ||
+ | } | ||
+ | if (n_grows == timeout) { | ||
+ | model_output <- NA | ||
+ | } | ||
+ | WBRef.close(wb1) | ||
+ | return(model_output) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This function contains the while-loop from above but also modifies (overrides) the '' | ||
+ | |||
+ | <code R> | ||
+ | plan(multisession, | ||
+ | |||
+ | system.time(model_outputs <- future_apply(params, | ||
+ | |||
+ | saveRDS(model_outputs, | ||
+ | </ | ||
+ | |||
+ | Through the use of '' | ||
+ | |||
+ | The only thing remaining is to analyze the output and plot the results: | ||
+ | |||
+ | <code R> | ||
+ | sensitivity:: | ||
+ | |||
+ | plot(m) | ||
+ | </ | ||
+ | |||
+ | This should now look something like this: | ||
+ | |||
+ | {{: | ||
+ | |||
tutorials/sensitivity-analysis-using-grolink-and-gror.1719322164.txt.gz · Last modified: 2024/06/25 15:29 by thomas