R packages

Several R packages provide methods because that sensitivity analysis. 2 of the widely imposed packages are sensitivity (Iooss et al., 2018) and also fast (Reusser, 2015). Fast provides the Fourier Amplitude Sensitivity test (FAST) as single an approach for sensitivity analysis. The implementation that FAST, however, is an extremely well suited to implement the in a workflow through SWATplusR. Sensitivity is a an extremely comprehensive arsenal of methods for sensitivity analysis (it actually includes the FAST method as well). The implementation in a workflow v SWATplusR is, however, much less flexible. In this example we will use 2 frequently applied methods for sensitivity analysis that are listed by these two R packages, the an approach of Solbol (1993) noted by sensitivity and FAST (Cukier et al., 1973) listed by fast. Most methods for sensitivity evaluation require a scalar model an outcome to assess the sensitivity of that output variable to alters in the inputs. Many goodness-of-fit functions are easily accessible from literary works to evaluate simulated time collection with observed time collection of that variable that result in scalar values. The hydroGOF package (Mauricio Zambrano-Bigiarini, 2017) summarizes generally used functions for the review of time collection of hydrological variables.

You are watching: Sensitivity analysis in r

Package installation

If you do not have installed any type of of the compelled R package, monitor the instructions because that the corresponding R package. Every one of the compelled R packages are obtainable from CRAN and also can be installed with the adhering to commands:


Loading demo data

The sensitivity analysis example supplies the SWAT+ demo project obtainable from SWATplusR. The demo project is a an easy model setup that a head watershed the the little River experimental Watershed (LREW; Bosch et al., 2007). You have the right to load the to your difficult drive together follows:

# The course where the SWAT demo project will be writtendemo_path "Define:/your/path"# Loading the SWAT+ demo task on your difficult drivepath_plus load_demo(dataset = "project", version = "plus", path = demo_path, revision = 57)

Model parameters

In the sensitivity analyses us will use 7 parameters that are frequently used for version calibration with respect come simulated discharge. In a an initial step we define the parameter names together these manage the parameter modification in the run_swat*() functions. If you desire to find out in detai just how to define the parameter names appropriately see the obtain started ar on ‘Model parameter alteration’:

par_names c("cn2.hru | adjust = abschg", "lat_ttime.hru | readjust = absval", "lat_len.hru | change = absval", "k.sol | readjust = pctchg", "z.sol | change = pctchg", "esco.hru | adjust = absval", "epco.hru | change = absval")

Parameter sampling

The Fourier Amplitude Sensitivity test (FAST) is a method to perform GSA with couple of model evaluations. It just requires a couple of simulations as soon as the number of parameters is low and strongly rises to tenth of thousands of version evaluations for much more than 20 parameters. To save the variety of model evaluations low we usage the 7 selected parameters above.

The FAST method requires a details parameter sampling design, the is obtainable in quick with the role fast_parameters().

par_fast fast_parameters( minimum = c(-15, 0.5, 10, -50, -50, 0, 0), best = c( 10, 50, 100, 50, 50, 1, 1), surname = par_names) %>% as_tibble()par_fast#> # A tibble: 167 x 7#> `cn2.hru | chan… `lat_ttime.hru … `lat_len.hru | … `k.sol | change…#> #> 1 -13.8 44.3 84.3 -29.5 #> 2 -11.2 32.7 52.3 12.0 #> 3 -8.67 21.1 20.3 47.0 #> 4 -6.11 9.45 31.1 5.42#> 5 -3.55 2.89 63.1 -36.1 #> 6 -0.994 14.5 95.1 -22.9 #> 7 1.57 26.1 73.4 18.7 #> 8 4.13 37.8 41.4 40.4 #> 9 6.69 49.4 10 -1.20#> 10 9.25 39.3 42.0 -42.8 #> # … through 157 much more rows, and 3 much more variables: `z.sol | adjust =#> # pctchg` , `esco.hru | change = absval` , `epco.hru | change#> # = absval`

The version runs that provided the parameter to adjust sampled with rapid are evaluated making use of the NSE (Nash and Sutcliffe, 1970) criterion for everyday discharge for the time duration 2003 come 2012.

The NSE() role is available from the hydroGOF package. The simulations space evaluated through the everyday observations the discharge for the period 2003 to 2007. The calculate NSE values deserve to than be offered to assess the sensitivity that the NSE to changes in parameter values with the role sensitivity() indigenous the rapid package:

nse_fast q_fast$simulation$q_sim %>% select(-date) %>% map_dbl(., ~NSE(.x/8.64, q_obs$discharge))sens_fast sensitivity(nse_fast, 7)

Visualization the the rapid sensitivities

To visualize the calculation sensitivities we very first arrange the outcomes in a tibble (Müller and also Wickham, 2019). That is a an excellent idea to location the parameters in the plot of their sensitivities. Therefore, we convert the parameter names to factors and also sort them according to their sensitivity results using the use of the forcats package (Wickham, 2019). Us plot the parameter ranking in a barplot utilizing ggplot2 (Wickham, 2016).

result_fast tibble(parameter = q_fast$parameter$definition$par_name, rapid = sens_fast) %>% mutate(parameter = factor(parameter) %>% fct_reorder(., fast))
ggplot(data = result_fast) + geom_col(aes(x = parameter, y = fast)) + xlab("Parameter") + ylab("Sensitivity") + coord_flip() + theme_bw()


Sensitivity evaluation with the method of Sobol

The an approach of Sobol is a reference method for GSA. Come implement the SWAT version in the GSA workflow through sensitivity a function has to be characterized that return the a scalar variable because that which the sensitivity is assessed.

To perform GSA with the method of Sobol 2 random to adjust of samples v the same sample size for the parameters that need to be analyzed space required.

par_bound tibble("cn2.hru | change = abschg" = c(-15, 10), "lat_ttime.hru | readjust = absval" = c(0.5, 50), "lat_len.hru | change = absval" = c(10, 100), "k.sol | readjust = pctchg" = c(-50, 50), "z.sol | change = pctchg" = c(-50, 50), "esco.hru | readjust = absval" = c(0, 1), "epco.hru | adjust = absval" = c(0, 1))n_par 7n_samp 500x1 data.frame(matrix(runif(n_par * n_samp), nrow = n_samp)) %>% set_names(., names(par_bound)) %>% map2_dfc(., par_bound, ~ (.x * (.y<2> - .y<1>) + .y<1>))x2 data.frame(matrix(runif(n_par * n_samp), nrow = n_samp)) %>% set_names(., names(par_bound)) %>% map2_dfc(., par_bound, ~ (.x * (.y<2> - .y<1>) + .y<1>))
To do the sensitivity analysis with using method of Sobol the complying with command has to be executed. In total 4000 version evaluations are crucial to analysis 7 parameters v 500 Sobol samples.

Visualization the the Sobol analysis

Similar come the image of the results with the FAST an approach the results of the GSA with the technique of Solbol are plotted.

plot_sobol sens_sobol$S %>% mutate(parameter = rownames(.)) %>% mutate(parameter = factor(parameter) %>% fct_reorder(., original))ggplot(data = plot_sobol) + geom_pointrange(aes(x = parameter, y = original , ymin = `min. C.i.`, ymax = `max. C.i.`)) + coord_flip() + xlab("Parameter") + ylab("Sensitivity") + theme_bw()


Bosch, D. D., Sheridan, J. M., Lowrance, R. R., Hubbard, R. K., Strickland, T. C., Feyereisen, G. W. And Sullivan, D. G.: small river experimental watershed database, Water resources Research, 43(9), doi:10.1029/2006wr005844, 2007.

Cukier, R. I., Fortuin, C. M., Shuler, K. E., Petschek, A. G. And Schaibly, J. H.: research of the sensitivity of combination reaction systems to uncertainties in price coefficients. I theory, The newspaper of chemical Physics, 59(8), 3873–3878, doi:10.1063/1.1680571, 1973.

Iooss, B., Janon, A., Pujol, G., Khalid Boumhaout, Veiga, S. D., Delage, T., Fruth, J., Gilquin, L., Guillaume, J., Le Gratiet, L., Lemaitre, P., Nelson, B. L., Monari, F., Oomen, R., Rakovec, O., Ramos, B., Roustant, O., Song, E., Staum, J., Sueur, R., Touati, T. And Weber, F.: Sensitivity: an international sensitivity analysis of design outputs. available from: https://CRAN.R-project.org/package=sensitivity (Accessed 5 march 2019), 2018.

Mauricio Zambrano-Bigiarini: HydroGOF: Goodness-of-fit functions for to compare of simulated and also observed hydrological time series., 2017.

Müller, K. And also Wickham, H.: Tibble: an easy data frames. available from: https://CRAN.R-project.org/package=tibble (Accessed 5 march 2019), 2019.

Nash, J. E. And also Sutcliffe, J. V.: River circulation forecasting through conceptual models part I - A discussion of principles, newspaper of Hydrology, 10(3), 282–290, doi:10.1016/0022-1694(70)90255-6, 1970.

Reusser, D.: Fast: Implementation that the fourier amplitude sensitivity test (fast). obtainable from: https://CRAN.R-project.org/package=fast (Accessed 5 march 2019), 2015.

Wickham, H.: ggplot2: Elegant Graphics for Data Analysis, Springer-Verlag new York. easily accessible from: http://ggplot2.org, 2016.

See more: Which Type Of Bond Is Found In Sodium Bromide Crystals? Which Type Of Bond Is Found In Sodium Bromide

Wickham, H.: Forcats: tools for working through categorical variables (factors). obtainable from: https://CRAN.R-project.org/package=forcats (Accessed 5 march 2019), 2019.